I'm trying to show display an html string in a textview. I used the Html.fromhtml method to load html string textview. But It failed to parse tag. Here is my html string
<style>u.style{color:#FF0000;}span.style2{color:#000000;}</style>
<u class="style"><span class="style2">some text</span></u>
I had tried Spannable String also, But It displays underline and underlined text in same color.I don't want to change text color.
s.setSpan(new ForegroundColorSpan(Color.CYAN), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Can anyone help me to create custom textview, which can support tag in textview?
for html you must use this :
mytext.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
also check this link http://developer.android.com/reference/android/text/Html.html#fromHtml%28java.lang.String%29
and This is a list of allowed HTML tags:
br
p
div
em
b
strong
cite
dfn
i
big
small
font
blockquote
tt
monospace
a
u
sup
sub
The style
and span
tags are not supported in TextView
.
What you can do is this:
String myHtmlString = Html.fromHtml("<u> <font color=\"#FF0000\"> some text </font> </u>");
FYI, here is a list of supported tags.
you should have to use like this
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
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