Reputation: 597
I have to develop one android application.
I have to display the textview using html.fromHtml .
Here this is my content:
**Hottie Mallika Sherawat speaks about the men whom she’s over the moon about**
In these text ,have aligned on html file like below:
<span style="color:#ff8c00;">Mallika Sherawat </span>
I have to highlight the that color on Mallika Sherawat text only on my android textview also.
How can i do ???
I have wrote below code:
String fullcontent = in.getStringExtra("FullContent");
full_content = fullcontent.substring(1);
lblContent = (TextView) findViewById(R.id.title1);
lblContent.setText(Html.fromHtml(full_content),TextView.BufferType.SPANNABLE);
Here the html.fromHtml is supported b,p,italic text..But why it is not supported for highlight the particular text ??? pls how can i do ???
Upvotes: 1
Views: 2877
Reputation: 133560
Here's a list of html tags supported by textview
http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
For using SpannableString
http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring
Example:
Using Spannable String
_tv.setText("");
SpannableString ss1= new SpannableString(s);
ss1.setSpan(new StyleSpan(Typeface.BOLD), 0, 23, 0);
ss1.setSpan(new StyleSpan(Typeface.ITALIC), 0, 23, 0);
ss1.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 23, 0);
_tv.setText(ss1);
Using Html
String text = "<font color=#cc0029>hello</font> <font color=#ffcc00>world</font>";
yourtextview.setText(Html.fromHtml(text));
Upvotes: 3
Reputation: 106
Try this...
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
Upvotes: 0