How to set TextView textStyle such as bold, italic

JustMe picture JustMe · Jun 1, 2011 · Viewed 493.8k times · Source

How to set TextView style (bold or italic) within Java and without using the XML layout?

In other words, I need to write android:textStyle with Java.

Answer

Tanmay Mandal picture Tanmay Mandal · Jun 1, 2011
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.NORMAL);

To keep the previous typeface

textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC)