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.

2
  • 1
    Try message.setText(Html.fromHtml(currentActivity.getResources().getString(R.string.txt_testing_step1_alert_message))); Commented Oct 28, 2015 at 9:12
  • try replacing < with &lt; Commented Oct 28, 2015 at 9:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, I didn't mentioned it but I also tried it but it doesn't work
@user2235615 Provide font color like <font color=\"#c5c5c5\">. Check this or Demo
It shown me as error - "Open quote is expected for attribute "color" associated with an element type "font"."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.