如何通过使用getString()设置粗体文本

Cuo*_*Huy 0 android getstring textview settext

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

这是我的代码:String.xml:

<string name="country"><b>AMERICA-default</b></string>
Run Code Online (Sandbox Code Playgroud)

我的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);
}
Run Code Online (Sandbox Code Playgroud)

Har*_*ana 5

Replace < with &lt; country value

<string name="country">&lt;b>AMERICA-default&lt;/b></string>
Run Code Online (Sandbox Code Playgroud)

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

tvCountry.setText(Html.fromHtml(getResources().getString(R.string.country)));
Run Code Online (Sandbox Code Playgroud)