在字符串中更改文本颜色?
问题描述:
可能重复:结果
Different在TextView的颜色XML定义
这可能是一个非常愚蠢的问题,但我想不出这一点。
我想要做的是改变字符串中的文本的颜色,就像这样:
+ colorRed你呢?
This is probably a really stupid question but I couldn't figure this out. What I want to do is change the color of the text within the string, like so: "Hi, how are" +colorRed " you?"
^试图改变单词你是红色。
^ trying to change the word "you" to be the color red.
答
我知道最简单的方法是只用html。
Easiest way I know is to just use html.
String color = "Hi, how are <font color='#EE0000'>you</font>";
**YOUR_TEXTVIEW**.setText(Html.fromHtml(color));
有关更多详细信息请参阅本