Android:为值/字符串中的特定单词着色

标签 android xml string colors

<分区>

所以我得到了这样一个字符串:

<string name="colorThis">This is red.</string>

我想要红色的“This”。有什么可能的方法吗?我发现常规的 XML 格式设置不起作用。我也知道如何给整个字符串上色。但是一个字?打住

最佳答案

您可以为此使用 html。 像这样尝试:

<string name="colorThis"><![CDATA[<font color="red">This is red.</font>]]></string>

或者像这样

<string name="colorThis"><![CDATA[<font color="#FF0000">This is red.</font>]]></string>

然后像这样设置文本:yourTextView.setText(Html.fromHtml(getResources().getString(R.string.colorThis)));

关于Android:为值/字符串中的特定单词着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20632908/

相关文章:

python - 使用 xmltodict 在 python 中从 xml 文件创建 json 文件

xml - 使用xpath部分搜索属性值

C++字符串数组char问题

ruby - 在 Ruby 中,试图将那些奇怪的引号转换为 "regular"引号

android - 底部在 flutter 中重载了 213 像素

Android NDK pthread_create 显示 “too many arguments, expected 1”

android - 同意 SDK : consentStatus become UNKNOWN again

注释的 Android Studio 代码样式

xml - 如何从 XPath 中的长字符串中选择合格的文本

c++ - 为什么 g++ 在编译时给我冲突错误?