Define font from asset folder in xml file android

Yawar picture Yawar · Nov 1, 2014 · Viewed 12.8k times · Source

I have created folder named fonts in my asset folder and put a .ttf file in it. And Assigning that fontfamily to my text like this

txtName.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/segoeui.ttf"));

But I want to assign this font in xml file. May be something like this.

<TextView
        android:id="@+id/txtName"
        style="@style/My_Name"
        android:fontFamily="@android:asset/fonts/segoeui"
         />

Answer

Sumit Jain picture Sumit Jain · Apr 16, 2018

To include ttf file in your app is lead to increase your app size.

Downloadable Font is best solution to use other fonts. Use following references:

document: https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html

sample: https://github.com/googlesamples/android-DownloadableFonts

and still you want to include fontFile then use following answer: https://stackoverflow.com/a/27588966/8240915