简体   繁体   中英

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. 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. Also a webview isn't a sollution.

Example 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. You can use <small> , <big> tags for Android HTML

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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