如documentation所述:
因此:
不幸的是,当我使用上面的代码时,出现以下错误:
cannot resolve method 'getFont(?)'
以前,我曾经做过以下事情:
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");
但是现在,当我尝试在 Assets 文件夹内创建字体文件夹时,它会自动在 res 文件夹内跳转。
我正在使用 android studio 2.3 。在此先感谢您的帮助。
最佳答案
使用支持库26中的此方法。
ResourcesCompat.getFont(context, R.font.your_font);
来源:
https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat.html