create typeface from font resource id

sziraqui picture sziraqui · Feb 8, 2018 · Viewed 19.8k times · Source

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 I thought asset manager will read from font resource directory but I was wrong. I am creating Typeface to set custom font for collapsingToolbarLayout.

I found this answer but it requires me to keep font in assets

Answer

sziraqui picture sziraqui · Feb 8, 2018

This worked

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

Found this in the tutorial link by @Eselfar