Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 804
JustMe Avatar asked Jun 01 '11 11:06

JustMe


People also ask

How do I set TextView to bold?

android:textStyle attribute is the first and one of the best way to make the text in TextView bold. just use “bold”. If you want to use bold and italic. Use pipeline symbol “|” .

How do I make a text on TextView bold in XML?

text. style. StyleSpan(Typeface. BOLD), start, end, Spannable.

How do I make bold text in Spannable?

SpannableString string = new SpannableString("Bold and italic text"); string. setSpan(new StyleSpan(Typeface. BOLD), 0, 4, Spannable.


1 Answers

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) 
like image 110
Tanmay Mandal Avatar answered Sep 28 '22 10:09

Tanmay Mandal