简体   繁体   中英

Highlight the textcolor in android html.fromHtml

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&nbsp;</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 ???

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));

Try this...

String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM