Android – How to set TextView textStyle such as bold, italic


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.

Best Solution

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)