Where should I put the “ttf” files in an Android project?

后端 未结 7 2020
眼角桃花
眼角桃花 2020-12-16 10:47

I\'m trying to use fonts in my project using Typeface. I copied the \"font.ttf\" into a folder named \"fonts\" inside \"assets\" folder. But eclipse do not allo

7条回答
  •  隐瞒了意图╮
    2020-12-16 11:14

    Since font organization and utilization has changes in Android 8 (API 26), it is now recommended to put your fonts into /res/font/ directory and access them with:

    (Typeface) ResourcesCompat.getFont(context, R.font.your_font_bold);
    

    which will return a Typeface object you needed.

提交回复
热议问题