2013-04-23 50 views
1

我必須開發一個android應用程序。我不得不使用html.fromHtml顯示textview。在android中突出顯示textcolor html.fromHtml

這裏,這是我的內容:

**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也。

我該怎麼辦?

我已經寫了下面的代碼:

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,斜體text..But爲什麼它不支持亮點特定文本???請問我該怎麼辦?

回答

3

這是一個被TextView的

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

支持的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); 

enter image description here

使用HTML

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

嗨跨度是支持或機器人html.fromHtml方法不suppoting ....我的HTML內容的風格是span..這是我的後端進程....那就是爲什麼要求 – user2218667 2013-04-23 06:28:02

+0

分開使用spannable字符串。檢查鏈接中的示例。它的工作 – Raghunandan 2013-04-23 06:29:12

+0

是的... HTML內容是從XML飼料....那麼我怎麼能單獨做...這是動態的字符串....動態字符串的任何解決方案? – user2218667 2013-04-23 06:39:19

0

嘗試......

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

您好span支持或不支持android html.fromHtml方法....我的html內容樣式是span..This是我的後端進程。 ..爲什麼問 – user2218667 2013-04-23 06:28:46