您的位置:首页 > 移动开发 > Android开发

android string.xml中格式资源字符串

2012-12-06 16:01 183 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: