2012-11-21 32 views

回答

2
String s = "Hi, how are <font color='red'>you</font>?"; 
textView.setText(Html.fromHtml(s), TextView.BufferType.SPANNABLE); 
4

我知道的最简单的方法就是使用html。

String color = "Hi, how are <font color='#EE0000'>you</font>"; 
**YOUR_TEXTVIEW**.setText(Html.fromHtml(color)); 

更多Detail Refer This

0

我认为最好的(和耗时更少)的方式是 - 使用Spannable。例如:

final String text = "Hi, how are "; 
final Spannable spanYou = new SpannableString("you"); 
spanYou.setSpan(new ForegroundColorSpan(Color.RED), 0, spanYou.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
textView.setText(text); 
textView.append(spanYou); 

Html.fromHtml()首先将您的文本解析为html,然后使用Spannable。