更改字符串颜色[重复]!

时间:2014-11-18 18:38:04

标签: android

String str = "Hello";

有没有办法改变字符串颜色? 这个问题可能是重复的,但所有答案都在谈论改变TextView颜色。 这个字符串将位于"文本区域"。类似于什么时候 用户输入单词hello,然后输出将是一个带有(某种颜色)的hello单词。

1 个答案:

答案 0 :(得分:1)

  

这个字符串将位于"文本区域"。当用户键入单词hello时,输出将是一个带有(某种颜色)的hello字。

我认为您的意思是用户将输入EditText。您可以使用以下代码更改EditText的文本颜色。

EditText et = (EditText) findViewById(R.id.editText);
// choose a hex code for color
et.setTextColor(Color.parseColor("#00ff00"));

您可以使用工具such as this one找到十六进制代码及其相应颜色的示例。