简体   繁体   English

更改从Strings.xml文件读取的文本颜色在android Eclipse的自定义对话框中不起作用

[英]Change text color that read from Strings.xml file doesn't work in custom Dialog on android Eclipse

My problem is that the text style(that case text color), doesn't work when the text imported from the strings.xml file. 我的问题是,当从strings.xml文件导入文本时,文本样式(这种情况下为文本颜色)不起作用。

The text style works fine in all other activities. 文字样式在所有其他活动中都可以正常工作。

The code is quite simple: 代码很简单:

this is the string from the strings.xml files: 这是来自strings.xml文件的字符串:

 <string name="txt_testing_step1_alert_message">Your sample needs to rest for 15 minutes. Press  \"<font color='#FF0000'>YES</font>\" to start the timer. Press "NO" to go back to previous screen.</string>

I tried also to use it like this: 我也尝试这样使用它:

 <string name="txt_testing_step1_alert_message">Your sample needs to rest for 15 minutes. Press  \"<font color='Red'>YES</font>\" to start the timer. Press "NO" to go back to previous screen.</string>

This is a part of my Java code that called to the relevant string: 这是我的Java代码中调用相关字符串的一部分:

message.setText(currentActivity.getResources().getString(R.string.txt_testing_step1_alert_message));

As you can see what I'm trying to do is to change only the "YES" word color to red. 如您所见,我正在尝试做的只是将“是”字样的颜色更改为红色。

The result of this code is black text color for all text. 该代码的结果是所有文本均为黑色文本颜色。

Do like 喜欢

message.setText(Html.fromHtml(currentActivity.getResources().getString(R.string.txt_testing_step1_alert_message)));

Workaround: 解决方法:

I try with below string 我尝试下面的字符串

<string name="new_text">Your sample needs to rest for 15 minutes. Press &lt;font color="#0000FF"&gt;YES&lt;/font&gt;  to start the timer. Press "NO" to go back to previous screen</string>

and it's working fine. 而且工作正常。

Output: 输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM