我试图创建一个隐藏导航栏和操作栏的库(我知道这是一种做事的hackish方式 - 但它只会在一个版本的Android和一个特定的设备模型上 - 所以它应该没问题 - 我们不需要全球兼容性 - 我们只需要它可以工作)
问题 - 我在创建库时遇到了一些错误:
The method getDecorView() is undefined for the type & The method getWindow() is undefined for the type
以及
Return type for the method is missing & Syntax error on token ".", { expected.
我试图添加:
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
正如另一篇SO文章所建议的那样 - 但我不能正确地实现它。
任何建议都表示赞赏。
public class HideNav{
// Hide Android Navigation bar
getWindow().getDecorView().setSystemUiVisibility(8);
// Hide Android Status Bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
Syntax error on token ".", { expected
The method getDecorView() is undefined for the type
The method getWindow() is undefined for the type
Return type for the method is missing
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
任何建议都表示赞赏。
我尝试使用以下评论在以下评论中实施该建议:
public class HideNav extends View{
public HideNav(Context context) {
super(context);
}
public void changeSomethingInWindow(){
// get a reference of the activity
Activity parent = (Activity)getContext();
// using the activity, get Window reference
Window window = parent.getWindow();
// using the reference of the window, do whatever you want :D
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
combined with:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HideNav view = new HideNav(this);
view.changeSomethingInWindow();
setContentView(view);
但是我得到了
FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.example.hidenav.HideNav at onCreate(ActivityMain.java:100)
是:
MaskUI view = new MaskUI(this);