I am trying to add lines with different colors to my TextView using html tags.
For whatever reason,
Html.fromHtml("<font color='#145A14'>text</font>");
won't show up colored in the TextView.
Html.fromHtml("<font color='#145A14'>text</font>");
Instead of above please use following
Html.fromHtml("<![CDATA[<font color='#145A14'>text</font>]]>");
This worked for me and I am sure it will also work for you.
Let me know in case of any issue.
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("<font color='#123456'>text</font>"));
will work, but:
text.setText(Html.fromHtml("<font color='#ff123456'>text</font>"));
won't!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With