【发布时间】:2017-01-27 05:26:11
【问题描述】:
我有这行代码工作:
PrintText += "<font color='#33B5E5'>P1</font>";
此行以天蓝色打印 P1,但 P1 可以根据应用程序上选择的语言进行更改,因此我想从 Strings.xml 中获取文本
在 Strings.xml 我有:
<string name="str_P1">P1</string>
我试过了:
PrintText += "<font color='#33B5E5'>getResources().getString(R.string.str_P1)</font>";
这一行在天蓝色而不是“P1”中打印“getResources().getString(R.string.str_P1)”
也试过这个: 字符串.xml:
<string name="str_P1">"<font color='#33B5E5'>P1</font>"</string>
代码:
PrintText += getResources().getString(R.string.str_P1);
此行以黑色打印“P1”,而不是所需的天蓝色。
要从 Strings.xml 获取 P1,我需要做什么才能在 skyblue 中打印“P1”?
【问题讨论】:
-
因为
getResources().getString(R.string.str_P1)在您的代码中被视为字符串。在getResources()行之前结束字符串引号 (") 并在之后开始
标签: xml android-studio text colors