我有这条线:
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");
但getAssets()参数似乎带来了一些错误,它用可怕的红线下划线,它说
对于 ProfileFragment 类型,方法 getAssets() 未定义
ProfileFragment 是我的类的名称,它扩展了 Fragment。
注意:字体样式也在 assets 文件夹中。
我有这条线:
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");
但getAssets()参数似乎带来了一些错误,它用可怕的红线下划线,它说
对于 ProfileFragment 类型,方法 getAssets() 未定义
ProfileFragment 是我的类的名称,它扩展了 Fragment。
注意:字体样式也在 assets 文件夹中。
您不能getAssets()直接从片段中获取。您必须使用 getActivity().getAssets()而不是仅使用getAssets().
用这个
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Delius-Regular.ttf");
代替
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");
阅读更多关于为 Android 片段设置自定义字体