So I have a layout that has a TextView
:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GLASSES RX EXPIRATION DATE"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:typeface="monospace" />
I also have a futura font stored in my assets/fonts/
folder. I know how to set the typeface with java but is there a way right in the xml layout to set the font to my embeded asset font?
No, there isn't a way to set a custom font in the xml layout beside the default ones, normal
, monospace
, sans
and serif
. You could make your own TextView
, with a custom attribute that could take the extra font in xml and use that instead of the normal TextView
class.
In the standard form, you will not be able to do it, but there is a way around it as mentioned by Luksprog. You basically need to
This will enable you to use your custom fonts without having to set it in java all over your application. Here's a tutorial for it.