I have a custom TextView
, to show html text. For pre-Nougat devices it works. As you already know on Nougat, fromHtml is deprecated and it needs a flag..so my code is like this
Spannable s = getRichText(text);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
super.setText(Html.fromHtml(s.toString(), Html.FROM_HTML_MODE_COMPACT, this, new HtmlHandler(getContext())), BufferType.SPANNABLE);
} else {
super.setText(Html.fromHtml(s.toString(), this, new HtmlHandler(getContext())), BufferType.SPANNABLE);
}
The problem it that, the HtmlHandler
class is never get called. (I have already tried all the flags).
On HtmlHandler
I handle tags and styles, eg background-color
, color
et cetera. I have implemented to get colors from rgb
, rgba
, hls
etc. But on Nougat it accepts only colors with hex, because on Nougat, fromHTML
can "read" colors and show them. Why is this happening? How can I keep my way for the colors? If you didn't understand something, or need more details, let me know.
The html I use for testing is
<p><strong>Server</strong><u> message</u><strong><u>!!!</strong></u> <span style="background-color: rgb(255,0,0);">Not working on Nugat</span></p>