【问题标题】:Android HTML span inside span doesn't cascade style跨度内的Android HTML跨度不层叠样式
【发布时间】:2020-07-28 13:45:11
【问题描述】:

我想使用 HTML 为 TextView 中的段着色。我有:

String myText = "normal text here <span style='color: red'> this should be red <span style='color: yellow'>but this should be yellow </span> and more red text </span> now normal text";
textView.setText(Html.fromHtml(myText, 0));

但是“但这应该是黄色的”文本仍然是红色的。我什至尝试过

<span style='color: yellow !important'>

它仍然是红色的。我怎样才能强制执行黄色部分?

【问题讨论】:

    标签: android html textview


    【解决方案1】:

    不使用spans,你这样用可以吗?

    String text = "normal text here<font color=#fc4903>this should be red</font> <font color=#ffcc00>but this should be yellow</font><font color=#fc4903>and more red text</font>now normal text ";
    textview.setText(Html.fromHtml(text))
    

    对不起,如果我误导了你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多