Android的多色彩于一体的TextView [英] Android multi color in one TextView
本文介绍了Android的多色彩于一体的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview">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);
这篇关于Android的多色彩于一体的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文