Skip to content Skip to sidebar Skip to footer

Create Typeface From Font Resource Id

I have tried using Typeface.createFromAsset(getAssets(),'font/myfont.ttf')); I know font directory should be in assets but in my case, I have an existing font resource directory so

Solution 1:

This worked

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

Found this in the tutorial link by @Eselfar

Solution 2:

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:

Typefacetypeface=  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 :

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

your font must be stored into the /font directory

enter image description here

Post a Comment for "Create Typeface From Font Resource Id"