2014-11-08 19 views
0

我想说明通过的setText()一个大胆的文字设定了一个大胆的文字,但我只是看到了一个文字是不是BOLD :(我该如何解决这个问题呢?如何使用的getString()

这里我代码: 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); 
} 

回答

2
Replace < with &lt; country value 

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

设置使用Html.fromHtml(资源字符串),其中s支持HTML标记。

tvCountry.setText(Html.fromHtml(getResources().getString(R.string.country))); 
+0

太棒了!我试了,我的文字是粗体:)非常感谢:D – 2014-11-10 08:51:05

+0

@ CuongTruongHuy,很高兴帮助你... – 2014-11-10 08:53:25

0

只需使用Typeface类:

tvCountry.setTypeface(null, Typeface.BOLD); 
+0

非常感谢你,它的工作! – 2014-11-10 08:49:53

0

使用它基于XML的文件,其中u creatd的TextView

android:textStyle="bold" 
+0

它确定但我必须使用setText(getResources()。getString(R.string.country)); – 2014-11-10 08:53:58

相关问题