create typeface from font resource id create typeface from font resource id android android

create typeface from font resource id


This worked

Typeface typeface = ResourcesCompat.getFont(this, R.font.app_font);

Found this in the tutorial link by @Eselfar


If you want to create the TypeFace from a font stored in assets folder,

enter image description here

you donĀ“t need to define the directory, just the name of the font:

Typeface typeface =  Typeface.createFromAsset(getAssets(),"app_font.ttf");

You can create the Typeface using the resource id of the font stored into the /font folder like this :

Typeface typeface = ResourcesCompat.getFont(this, R.font.app_font);

your font must be stored into the /font directory

enter image description here