簡體   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