1

I want to show a BOLD text by setText() , but i just saw a text is not BOLD :( How can I solve this problem ?

Here my code : String.xml :

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

my Java code :

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);
}

3 Answers3

6
Replace < with &lt; country value

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

Set resource string using Html.fromHtml() which support html tag.

tvCountry.setText(Html.fromHtml(getResources().getString(R.string.country)));
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
0

Just use the Typeface class :

tvCountry.setTypeface(null, Typeface.BOLD);
Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
0

Use it on Xml file where u creatd textview

android:textStyle="bold"
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28