2

My problem is that the text style(that case text color), doesn't work when the text imported from the strings.xml file.

The text style works fine in all other activities.

The code is quite simple:

this is the string from the strings.xml files:

 <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:

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.

user2235615
  • 1,513
  • 3
  • 17
  • 37

1 Answers1

4

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:

enter image description here

M D
  • 47,665
  • 9
  • 93
  • 114
  • Sorry, I didn't mentioned it but I also tried it but it doesn't work – user2235615 Oct 28 '15 at 09:19
  • @user2235615 Provide font color like ``. [Check this](http://stackoverflow.com/questions/10392163/using-multiple-text-colors-in-androids-textview-html-fromhtml) or [Demo](http://android4beginners.com/2013/07/lesson-1-5-how-to-color-part-of-the-text-and-use-alpha-channel-in-textview/) – M D Oct 28 '15 at 09:21
  • It shown me as error - "Open quote is expected for attribute "color" associated with an element type "font"." – user2235615 Oct 28 '15 at 09:23