create typeface from font resource id

后端 未结 2 999
余生分开走
余生分开走 2020-12-09 14:18

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 exist

相关标签:
2条回答
  • 2020-12-09 14:59

    This worked

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

    Found this in the tutorial link by @Eselfar

    0 讨论(0)
  • 2020-12-09 15:12

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

    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

    0 讨论(0)
提交回复
热议问题