使用内联样式在 textview html 中显示 [英] Show in textview html with inline styles
问题描述
我需要在我的应用中显示带有 内联样式 的 html.有很多文本必须在不同的视图中,所以我不能使用 Webview(我尝试使用很多 Webview,但应用程序变得非常慢).据我所知 TextView 可以显示 html但它不能显示带有内联样式的 html.所以我该怎么做?有什么方法可以显示它或只生成带有内联样式的html的简单标签的html?
I need to show html with inline styles in my app. There are a lot of text that must be in different views so I can't use Webview(I tried to use a lot of Webviews but the app becomes very slow ).As I know TextView can show html but it can`t show html with inline styles. So, what should I do? Is there any way to show it or to generate only html with simple tags from html with inline styles?
所以我需要像这样显示html:
So I need to show html like this:
<p style="text-align: center;"><span style="color: #ff0000; font-size: 36pt; font-family: 'comic sans ms', sans-serif;">Article Title</span></p>
但 TextView 无法理解样式.
But TextView can`t understand style.
推荐答案
Android 原生 TextView
不支持所有 HTML 标签和功能.它只支持 少数标签和属性.因此,在您的情况下,您可能需要考虑几个选项.
Android native TextView
doesn't support all HTML tags and features. It only does support a few tags and properties. So, in your case, there's a couple of options which you may want to consider.
使用
WebView
显示富文本.但是,WebView
又重又慢.
Use
WebView
to show rich texts. However,WebView
s are too heavy and slow.
使用改进原生 TextView
并支持更多 HTML 标签的 3rd 方库.例如:HTML-TextView.
Use 3rd party libraries that improve native TextView
and support more HTML tags. For example: HTML-TextView.
这篇关于使用内联样式在 textview html 中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!