How do you change text to bold in Android?
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>");
Admin
Updated on January 08, 2022Comments
-
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 over 8 yearsLet me know the result
-
Dov Benyomin Sohacheski over 6 yearsYou should include a brief explanation of your answer to better describe its use case and implementation.
-
nvoigt over 6 yearsThis does not ad anything new to the existing answers.
-
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 about 3 yearsStackOverflow requires answers to be posted in English.
-
Arty Morris about 3 yearsUse the translator!
-
Mark Rotteveel about 3 yearsNo, it is your responsibility to post in English, otherwise you can use ru.stackoverflow.com
-
gumuruh over 2 yearswhat if the editTextView components,,... is it possible to bold each line differently?
-
Sudipta Som over 2 yearsYes Its possible