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
In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With