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