How do you change text to bold in Android?

515,577

Solution 1

To do this in the layout.xml file:

android:textStyle

Examples:

android:textStyle="bold|italic"

Programmatically the method is:

setTypeface(Typeface tf)

Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int) to get the appearance that you actually want.

Solution 2

Here is the solution

TextView questionValue = (TextView) findViewById(R.layout.TextView01);
questionValue.setTypeface(null, Typeface.BOLD);

Solution 3

Simply you can do the following:

Set the attribute in XML

  android:textStyle="bold"

Programatically the method is:

TextView Tv = (TextView) findViewById(R.id.TextView);

Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);

Tv.setTypeface(boldTypeface);

Hope this helps you thank you.

Solution 4

In XML

android:textStyle="bold" //only bold
android:textStyle="italic" //only italic
android:textStyle="bold|italic" //bold & italic

You can only use specific fonts sans, serif & monospace via xml, Java code can use custom fonts

android:typeface="monospace" // or sans or serif

Programmatically (Java code)

TextView textView = (TextView) findViewById(R.id.TextView1);

textView.setTypeface(Typeface.SANS_SERIF); //only font style
textView.setTypeface(null,Typeface.BOLD); //only text style(only bold)
textView.setTypeface(null,Typeface.BOLD_ITALIC); //only text style(bold & italic)
textView.setTypeface(Typeface.SANS_SERIF,Typeface.BOLD); 
                                         //font style & text style(only bold)
textView.setTypeface(Typeface.SANS_SERIF,Typeface.BOLD_ITALIC);
                                         //font style & text style(bold & italic)

Solution 5

For case where you are using custom fonts, but do not have bold typeface for the font you can use:

myTextView.setText(Html.fromHtml("<b>" + myText + "</b>");
Share:
515,577
Admin
Author by

Admin

Updated on January 08, 2022

Comments

  • Admin
    Admin over 2 years

    How do you change text/font settings in an Android TextView?

    For example, how do you make the text bold?

  • saeed
    saeed over 8 years
    Let me know the result
  • Dov Benyomin Sohacheski
    Dov Benyomin Sohacheski over 6 years
    You should include a brief explanation of your answer to better describe its use case and implementation.
  • nvoigt
    nvoigt over 6 years
    This does not ad anything new to the existing answers.
  • CoolMind
    CoolMind over 5 years
    @nvoigt, his answer differs from many others, at least the second line. Probably it is better than other solutions. I think it is captured from stackoverflow.com/questions/6200533/….
  • Mark Rotteveel
    Mark Rotteveel about 3 years
    StackOverflow requires answers to be posted in English.
  • Arty Morris
    Arty Morris about 3 years
    Use the translator!
  • Mark Rotteveel
    Mark Rotteveel about 3 years
    No, it is your responsibility to post in English, otherwise you can use ru.stackoverflow.com
  • gumuruh
    gumuruh over 2 years
    what if the editTextView components,,... is it possible to bold each line differently?
  • Sudipta Som
    Sudipta Som over 2 years
    Yes Its possible