CEN*_*EDE 2 android interface android-typeface
所以我有这个界面:
public interface Utils{
static final Typeface FONT = Typeface.createFromAsset(getAssets(), "fonts/font.ttf");;
}
Run Code Online (Sandbox Code Playgroud)
我有一个错误getAssets(),它说方法getAssets()未定义为类型Utils为什么是这样?请帮忙谢谢:)
您的Utils类没有名为的方法getAssets().我假设您要使用Android Context类中的那个.这意味着您需要有一个Context要调用的对象getAssets().如果没有关于您的确切应用程序设计的更多详细信息,我无法再帮助您.
一种可能的解决方案是创建一个Activity子类,您的所有其他活动都会扩展.您还需要遵守活动生命周期:
public abstract FontActivity extends Activity {
private Typeface font;
@Override
public onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
font = Typeface.createFromAsset(getAssets(), "fonts/font.ttf");
}
}
Run Code Online (Sandbox Code Playgroud)
现在延伸FontActivity而不是Activity.