简体   繁体   English

Android TextView fromHtml() 如何支持不支持的css 样式、文字大小?

[英]Android TextView fromHtml() how to support unsupported css style, text size?

I'm using this:我正在使用这个:

HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY);

How to add support of text size regarding a fact that font-size isn't natively supported?关于字体大小不受本机支持的事实,如何添加对文本大小的支持?

I don't want to override whole paragraph text - other styles works well.我不想覆盖整个段落文本 - 其他 styles 效果很好。 Using regex or parse html through different library may lead to problems as part of a text may have bigger font or parser may work differently.使用正则表达式或通过不同的库解析 html 可能会导致问题,因为文本的一部分可能具有更大的字体或解析器可能工作不同。 Also a webview isn't a sollution. webview 也不是解决方案。

Example html:示例 html:

 <p style="font-size:30px">TEST</p>

Android HTML did not support all the tags of HTML. Font color is working fine with Android HTML, but font size is not supported. Android HTML 不支持 HTML 的所有标签。字体颜色适用于 Android HTML,但不支持字体大小。 You can use <small> , <big> tags for Android HTML您可以对 Android HTML 使用<small> , <big>标签

Html.fromHtml("<big>" + "First name" + "</big>" + "<br />" + "<small>" + "Last name" + "</small>", Html.FROM_HTML_MODE_LEGACY);

You can check here which tags are supported with Android HTML您可以在此处查看Android HTML 支持哪些标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM