android string.xml中格式资源字符串
16lz
2021-12-09
string.xml中格式化字符串,并设置颜色等html标签:
注意前后加: "<![CDATA[" 和 "]]>"
<string name="lottery_num_sum"><![CDATA[注数:<font color=\'red\'>%1$d</font>注 金额:<font color=\'red\'>%2$d</font>元]]></string>
代码中使用:
String tip = String.format(getResources().getString(R.string.lottery_num_sum), num, num * 2);
// format html text
Spanned source = Html.fromHtml(tip);
mTvSelectNumTip.setText(source);
注意前后加: "<![CDATA[" 和 "]]>"
<string name="lottery_num_sum"><![CDATA[注数:<font color=\'red\'>%1$d</font>注 金额:<font color=\'red\'>%2$d</font>元]]></string>
代码中使用:
String tip = String.format(getResources().getString(R.string.lottery_num_sum), num, num * 2);
// format html text
Spanned source = Html.fromHtml(tip);
mTvSelectNumTip.setText(source);
更多相关文章
- android 中使用TextView实现分段显示不同颜色的字符串
- exp: 修改Android中strings.xml文件, 动态改变数据
- Android(安卓)中数据库查询方法 query() 中的 select
- android中SqLite query中用selectionArgs处理字符传值
- 修改系统Android版本,版本号
- 怎么去掉联系人、通话记录、拨号列表界面中的电话号码中间的空格
- 获取Android系统信息
- android 解析xml字符串
- android 解析xml字符串