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.
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 “|” .
text. style. StyleSpan(Typeface. BOLD), start, end, Spannable.
SpannableString string = new SpannableString("Bold and italic text"); string. setSpan(new StyleSpan(Typeface. BOLD), 0, 4, Spannable.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With