可能重复: Is有可能有一个TextView里面的多种样式?
我希望我的TextView,以显示其在红色和黑色文字别人的某些部分。它的内容(文本)是动态创建的,我不知道有多少的话会是红色的。
I want my TextView to show some part of its text in red and others in black. It's content (the text) is created dynamically and i don't know how many words will be red colored.
有没有办法做到这一点像HTML,CSS?
Is there any way to do this like in html-css?
您可以使用Spannable来实现你想要的。
You can use Spannable to achieve what you want.
String text = "This is <font color='red'>red</font>. This is <font color='blue'>blue</font>.";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);