Android Html.fromHtml()在嵌套文本样式上无法正常工作 [英] Android Html.fromHtml() does not work correctly on nested text style

查看:69
本文介绍了Android Html.fromHtml()在嵌套文本样式上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示HTML

"<html><body><font color=\"black\">
In the name of <font color=\"blue\"><b> God</b></font>
the compassionate, the merciful</font></body><html>"

在TextView中.因此,我使用了 Html.fromHtml(),但与浏览器相比输出是不同的.

in a TextView. So I have used Html.fromHtml(), but output is different compared with browsers.

不同之处在于,上帝"一词在TextView中并未显示为蓝色.

The difference is that the word "God" does not appear in blue color in the TextView.

代码:

textView.setText("<html><body><font color=\"black\">
  In the name of <font color=\"blue\"><b> God</b></font>
  the compassionate, the merciful</font></body><html>");

推荐答案

尝试如下:

textView.setText(Html.fromHtml("<html><body>In the name of<font color=blue><b> God </b></font>the compassionate, the merciful</body><html>"));

注意:黑色是默认颜色,因此您不必对黑色使用< font> 标记.

Note: Black is default color so you dont have to use <font> tag for black color.

如果您想使用,则以正确的方式(例如 GRAY BLUE )完成标签:

if you want to use then complete tags right way like (for example for GRAY and BLUE):

textView.setText(Html.fromHtml("<html><body><font color=gray>In the name of </font><font color=blue><b> God </b></font><font color=gray>the compassionate, the merciful</font></body><html>"));

这篇关于Android Html.fromHtml()在嵌套文本样式上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆