Android Html.fromHtml(String) doesn't work for text

后端 未结 12 1491
逝去的感伤
逝去的感伤 2020-12-23 19:32

I am trying to add lines with different colors to my TextView using html tags.

For whatever reason,

    Html.fromHtml(\"

        
12条回答
  •  天涯浪人
    2020-12-23 20:07

    My answer involves guesswork about your code, but here goes:

    When you use the font tag: DO NOT include an alpha channel so that your hex string looks like "#ff123456". If you use Integer.toHexString(), you will have an alpha channel in that result.

    It worked when i used substring(2) on my hex string from rescource.

    To sum up:

    text.setText(Html.fromHtml("text"));
    

    will work, but:

    text.setText(Html.fromHtml("text"));
    

    won't!

提交回复
热议问题