gpt4 book ai didi

android - 如何更改存储在 strings.xml 中的字符串中某些单词的颜色?

转载 作者:太空狗 更新时间:2023-10-29 15:52:07 26 4
gpt4 key购买 nike

我找到了一些关于如何更改存储在 strings.xml 中的字符串的特定字符和单词的颜色的解决方案,但是,它对我不起作用。我有以下字符串

<string name="my_string">
Humpty Dumpty sat on a <font fgcolor="#FF0000">wall</font> Humpty Dumpty had a great <font fgcolor="#FF0000">fall</font></string>

我原以为 wall 和 fall 的颜色是#FF0000(红色),但是它们根本不显示。经过进一步研究,我了解到您必须声明 alpha channel ,所以我将字符串更新为

<string name="my_string">
Humpty Dumpty sat on a <font fgcolor="#FFFF0000">wall</font> Humpty Dumpty had a great <font fgcolor="#FFFF0000">fall</font></string>

我声明的 alpha channel 是完全不透明的,但结果保持不变。

最后,我也试过使用CDDATA,这是我的尝试。

<string name="my_string"><![CDATA[
Humpty Dumpty sat on a <font color=\'#FF0000\'>wall</font> Humpty Dumpty had a great <font color=\'#FF0000\'>fall</font>]]</string>

我还做错了什么?提前致谢!

最佳答案

你应该使用这样的东西。

textView.setText(Html.fromHtml(getString(R.string.some_text)));

并且您的 strings.xml 应包含如下字符串。

<string name="some_text"><![CDATA[<font color=\'#cc0029\'>Some</font> random <font color=\'#ffcc00\'>text</font>]]></string>

检查 here了解更多详情。

关于android - 如何更改存储在 strings.xml 中的字符串中某些单词的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com