Android TextView 中的 CSS [英] CSS in TextView Android
问题描述
我有一个 html 字符串,我想在 TextView 中显示它.html 字符串具有 css 内联样式,并且在标题中也具有 css.想问一下能否在TextView中用css显示html字符串?
I have a html string that I want to display in TextView. The html string has css inline style and also css in header. I would like to ask if I can display the html string with css in TextView?
我试过 Html.fromHtml()
,但 css 不适用.
I tried Html.fromHtml()
, but the css doesn't apply.
推荐答案
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
显示富文本.但是,WebViews
太重且太慢了.
Use WebView
to show rich texts. However, WebViews
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.
这篇关于Android TextView 中的 CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!