Android textView解析HTML Html.fromHtml的使用

在android API 24 中,Html.fromHtml(String source) 已经过时。
为什么过时?因为有个Bug,解析后的文本,块元素之间换行默认为两行,而且无法更改。
推荐使用 Html.fromHtml(String source,int flags)

Flags:

FROM_HTML_MODE_COMPACT:html 块元素之间使用一个换行符分隔
FROM_HTML_MODE_LEGACY:html 块元素之间使用两个换行符分隔

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
              textView.setText(Html.fromHtml(content,Html.FROM_HTML_MODE_COMPACT));
        }else {
            textView.setText(Html.fromHtml(content);
        }

解析以下文本:

(1).Name: Toking Hazard by Joking Hazard

(2).Material: Paper

(3).Package: Box


50 Marijuana themed cards to heighten your Joking Hazard experience.

This is an expansion pack. It requires Joking Hazard to play

In addition to the cards, there is a secret in each box!

The box is OVERSIZED to fit the surprise


解析前:


image.png

解析后:


image.png

你可能感兴趣的:(Android textView解析HTML Html.fromHtml的使用)