Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改字符串颜色[重复]!_Android - Fatal编程技术网

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

Android 更改字符串颜色[重复]!,android,Android,有没有办法改变字符串的颜色? 这个问题可能是重复的,但所有的答案都是关于更改TextView颜色的。 此字符串将位于“文本区域”。类似于 用户键入单词hello,然后输出一个带有(某种颜色)的hello单词 此字符串将位于“文本区域”。类似于当用户键入单词hello时,输出将是一个带有(某种颜色)的hello单词 我假设您的意思是用户将在编辑文本中键入内容。您可以使用以下代码更改编辑文本的文本颜色 String str = "Hello"; 您可以使用工具找到十六进制代码及其相应颜色的示例。请

有没有办法改变字符串的颜色? 这个问题可能是重复的,但所有的答案都是关于更改TextView颜色的。 此字符串将位于“文本区域”。类似于 用户键入单词hello,然后输出一个带有(某种颜色)的hello单词

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

我假设您的意思是用户将在
编辑文本中键入内容。您可以使用以下代码更改编辑文本的文本颜色

String str = "Hello";

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

请更具体地回答这个问题,您在哪里使用该字符串?所有答案都涉及到更改
文本视图
颜色,因为
字符串
没有颜色。只有显示它的UI组件具有颜色属性。作为对象的字符串本身没有颜色“编码”到它们中。我在示例中的意思是双引号之间的单词“…”。但我意识到字符串本身就是一个对象,没有像抗坏血酸的评论那样将颜色“编码”到字符串中。
EditText et = (EditText) findViewById(R.id.editText);
// choose a hex code for color
et.setTextColor(Color.parseColor("#00ff00"));