0

我想通过 setText() 显示一个 BOLD 文本,但我刚刚看到一个文本不是 BOLD :( 我该如何解决这个问题?

这是我的代码: String.xml :

<string name="country"><b>AMERICA-default</b></string>

我的 Java 代码:

Resources resources;
TextView tvCountry;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Log.d("test","onCreate()-second Activity");
    setContentView(R.layout.activity_second);

    resources = getResources();
    tvCountry = (TextView) findViewById(R.id.tvCountry);
    tvCountry.setText(resources.getString(R.string.country));//its not working !Text is not bold!
    //CANNOT USE : tvCountry.setText(R.string.country);
}
4

3 回答 3

5
Replace < with &lt; country value

<string name="country">&lt;b>AMERICA-default&lt;/b></string>

使用支持 html 标签的 Html.fromHtml() 设置资源字符串。

tvCountry.setText(Html.fromHtml(getResources().getString(R.string.country)));
于 2014-11-08T06:56:44.567 回答
0

只需使用Typeface类:

tvCountry.setTypeface(null, Typeface.BOLD);
于 2014-11-08T06:58:44.520 回答
0

在您创建 textview 的 Xml 文件上使用它

android:textStyle="bold"
于 2014-11-08T07:02:34.250 回答