变色里面的strings.xml [英] Change color inside strings.xml

查看:258
本文介绍了变色里面的strings.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人,并想知道如何更改字体的strings.xml文件中的颜色在一个字符串变量。

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.

例如我有:

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

我只是将其显示为红色和蓝色

I just it to display as red and blue

感谢名单

推荐答案

试试这个

有关红色,

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

有关蓝,

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

在Java的code,

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));

这篇关于变色里面的strings.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆