CEN*_*EDE 3 android fragment typeface android-fragments
我有这条线:
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");
Run Code Online (Sandbox Code Playgroud)
但该getAssets()参数似乎带来了一些错误,它用可怕的红线加下划线,它说
对于类型ProfileFragment,方法getAssets()未定义
ProfileFragment是我的类的名称,它扩展了Fragment.
注意:字体样式也在assets文件夹中.
你无法getAssets()直接从片段中获取.您必须使用 getActivity().getAssets()而不是仅使用getAssets().
用这个
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Delius-Regular.ttf");
Run Code Online (Sandbox Code Playgroud)
代替
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");
Run Code Online (Sandbox Code Playgroud)
阅读有关为Android片段设置自定义字体的更多信息
| 归档时间: |
|
| 查看次数: |
4651 次 |
| 最近记录: |