I am using textview in my application. In that I need to change the typeface for the textview programmatically. In a button click function i need to change the textview typeface. If typeface is Normal means i need to convert to Bold(Vice versa). If anybody knows the answer means kindly share with me. Thanks.
Asked
Active
Viewed 3.9k times
3 Answers
39
To make your textView bold programmatically do:
textView.setTypeface(null, Typeface.BOLD);
To set it back to normal do:
textView.setTypeface(null, Typeface.NORMAL);
To get the current typeface use getTypeface()
http://developer.android.com/reference/android/widget/TextView.html#getTypeface()

Ken Wolf
- 23,133
- 6
- 63
- 84
-
Hi wolf.... This is working.. how can i get the typeface of textview? – Arunraj Jeyaraj Jul 15 '13 at 13:30
-
In a single button click i need to convert the typeface. If normal means bold and bold means normal. Again and again.... – Arunraj Jeyaraj Jul 15 '13 at 13:33
-
Unfortunately I can't immediately find a way to get whether it is BOLD or NORMAL from the textView object. I suggest you store your own boolean value and update accordingly. – Ken Wolf Jul 15 '13 at 13:40
-
ok wolf. If u knowing someother solution na, juz share with me. – Arunraj Jeyaraj Jul 15 '13 at 13:48
-
After setting italic, It only comes back to normal once, then switching back to italics stays like that (same code). – FirstOne Jul 11 '18 at 20:07
1
setTypeface(Typeface tf, int style)
Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.
From the Android documentation

karel
- 5,489
- 46
- 45
- 50

Gabe Sechan
- 90,003
- 9
- 87
- 127
1
try this
TextView textview= (TextView) findViewById(R.id.appname)
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.BOLD_ITALIC);

Sunil Kumar
- 7,086
- 4
- 32
- 50