I have a TextView
and I want to show multi-colored text in that. I am using html.fromHtml
for this, but it is not showing any color.
My code is:
//statusToShow is a String
Log.d("html ==>", statusToShow) ;
RStatus.setText(Html.fromHtml(statusToShow),
TextView.BufferType.SPANNABLE);
Value from Log is:
<span style='background-color:#80B5FF;color:#fff'>C</span> <span style='background-color:#CF8DEA;color:#fff'>P</span> <span style='background-color:red;color:#fff'>E</span> <span style='background-color:green;color:#fff'>D</span>
Not all tags are supported, list of supported tags is here: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
Try using Spannable
like this:
Spannable WordtoSpan = new SpannableString("Text To Span");
WordtoSpan.setSpan(new BackgroundColorSpan(Color.BLUE), 0, 4,
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
This will make the background color of Text
Blue.
Hope this helps.
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