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 に答える