【发布时间】:2016-03-17 09:43:53
【问题描述】:
我有这样的代码:
strings.xml
<string name="message1">Your money: <b>1000</b> <b>2000</b></string>
<string name="message2">Your money: <b>%1$s</b> <b>%2$s</b></string>
我想在 TextView 中显示它
MainActivity.java
// This one will render 1000 and 2000 in bold correctly
TextView mText1 = (TextView) findViewById(R.id.message1);
mText1.setText(getText(R.string.message1));
// This one fail to render 1000 and 2000 in bold
int val1 = 1000, val2 = 2000;
TextView mText2 = (TextView) findViewById(R.id.message2);
mText1.setText(String.format(getText(R.string.message2).toString(), val1, val2));
我想让我可以通过将 String.format 应用于 android 字符串资源来格式化粗体/斜体文本。
【问题讨论】:
-
你可能想看看SpannableString
标签: java android string formatting textview