【发布时间】:2015-07-04 04:21:19
【问题描述】:
我希望用两个不同颜色的文本设置单个 TextView,我已经阅读了文档
Single TextView with multiple colored text
代码 A 运行良好!
代码B从资源文件中获取字符串,但是无法显示字体颜色,为什么?
代码 A
TextView my=(TextView) findViewById(R.id.tVTitleOld);
String text = "<font color='#cc0029'>Hello</font> the <font color='#ffcc00'>world</font>";
my.setText(Html.fromHtml(text));
代码 B
TextView my=(TextView) findViewById(R.id.tVTitleOld);
String text = getResources().getString(R.string.TitleOld);
my.setText(Html.fromHtml(text));
<string name="TitleOld"><font color='#cc0029'>Hello</font> the new <font color='#ffcc00'>world</font></string>
【问题讨论】:
标签: android