Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color inside strings.xml

Tags:

android

I am new to android, and would like to know how do I change the color of font inside the strings.xml file in a string tag.

for example I have:

  <string name="hello_world">Hello world!</string> 

I just want it to display as red and blue

thanx

like image 397
Bohrend Avatar asked Oct 28 '13 08:10

Bohrend


People also ask

How do I change text color in XML?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .


1 Answers

Try this

For red color,

<string name="hello_worldRed"><![CDATA[<b><font color=#FF0000>Hello world!</font></b>]]></string> 

For blue,

<string name="hello_worldBlue"><![CDATA[<b><font color=#0000FF>Hello world!</font></b>]]></string> 

In java code,

//red color text TextView redColorTextView = (TextView)findViewById(R.id.redText); String redString = getResources().getString(R.string.hello_worldRed) redColorTextView.setText(Html.fromHtml(redString));  //Blue color text TextView blueColorTextView = (TextView)findViewById(R.id.blueText); String blueString = getResources().getString(R.string.hello_worldBlue) blueColorTextView.setText(Html.fromHtml(blueString)); 
like image 181
Silambarasan Poonguti Avatar answered Nov 06 '22 23:11

Silambarasan Poonguti