简体   繁体   中英

TextView doesn't apply HTML styles using Html.fromHtml

I try to display an HTML text with its styles, but the text is shown without styling.

  1. Is this normal behavior? It possible?
  2. Is there a nice way to extract the styling from the HTML and apply it to my view?

In my code there are two numbers, one should be red and the other should be striped. In action, they both seems as simple text.

Here is my code:

String str = "<span>&nbsp <span  dir=\"rtl\" style=\"text-align:right;color:#ff0000;\">  20.00</span>&nbsp;&nbsp;<span dir=\"rtl\" style=\"text-align:right;text-decoration: line-through;\">26.99 </span></span>";
Spanned spanned = Html.fromHtml(str);
txtView.setText(spanned);

not all the html tags are supported ( take a look here)

In my experience I have seen worked only div and p...

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