方法一:
设置activity的theme属性隐藏标题栏和状态栏,然后在onWindowFocusChanged方法中调用方法
mLCDChangeLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
mLCDChangeLayout可以是该activity布局中的任意一个控件,前一个flags主要实现隐藏NavigationBar的功能,后一个flags实现触摸不会弹出NavigationBar,只有下拉状态栏等一些系统手势时才会弹出。
方式二:
activity属性不用设置,直接在activity中加入如下方法:
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if( hasFocus ) { hideNavigationBar(); } } private void hideNavigationBar() { // TODO Auto-generated method stub final View decorView = getWindow().getDecorView(); final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; decorView.setSystemUiVisibility(flags); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(flags); } } }); }
然后在onWindowFocusChanged方法中调用hideNavigationBar的方法即可,原理与方式一类似。