繁体   English   中英

突出显示android html.fromHtml中的textcolor

[英]Highlight the textcolor in android html.fromHtml

我必须开发一个Android应用程序。

我必须使用html.fromHtml显示textview。

这是我的内容:

**Hottie Mallika Sherawat speaks about the men whom she’s over the moon about**

在这些文本中,已在html文件上对齐如下:

   <span style="color:#ff8c00;">Mallika Sherawat&nbsp;</span> 

我必须在我的android textview上突出显示Mallika Sherawat文本上的那种颜色。

我能怎么做 ???

我写了下面的代码:

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

这里html.fromHtml支持b,p,斜体文本..但是为什么不支持突出显示特定文本??? 请问我该怎么办?

这是textview支持的html标签列表

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

用于使用SpannableString

http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring

例:

使用Spannable字符串

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

在此输入图像描述

使用Html

String text = "<font color=#cc0029>hello</font> <font color=#ffcc00>world</font>";
yourtextview.setText(Html.fromHtml(text));

尝试这个...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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