How to set TextView
style (bold ot italic) with in Java and without using XML layout?
In other words I need to write android:textStyle
with Java.
How to set TextView
style (bold ot italic) with in Java and without using XML layout?
In other words I need to write android:textStyle
with Java.
This is the only thing that worked for me on a OnePlus 5T configured with the OnePlus Slate™ font:
Other methods would make it fall back to Roboto when either BOLD or NORMAL.
Try this:
In my case:
1 - set text
2 - set typeface
One way you can do is :
Another option if you want to keep the previous typeface and don't want to lose previously applied then:
Simply if you want to make text bold. write this line in your layout in text view property
Programmatically:
You can do programmatically using
setTypeface()
method:Below is the code for default Typeface
and if you want to set custom Typeface:
XML:
You can set directly in XML file in
<TextView />
like this:Or you can set your fav font (from assets). for more info see link