android string.xml中格式资源字符串
16lz
2021-01-23
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实现分段显示不同颜色的字符串
- android 解析xml字符串
- android字符串 优化(一)
- Android中base64加密后的字符串带有“\n”导致出错的问题解决
- %1$s %1$d Android string (java & Android 格式化字符串)
- Android中字符串的拆分-split
- iphone/android比较学习之──图片、文件、字符串
- Android资源文件 - 使用资源存储字符串 颜色 尺寸 整型 布尔值
- 处理固定宽度下的长字符串绘制(Android)