我隐藏了导航栏(请参阅下文),但是当我按下操作栏上的菜单按钮时,导航栏会立即出现。
我可以藏导航吗?永久吧?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
setContentView(R.layout.activity_fomenu);
}
最佳答案
看一下documentation。它说隐藏导航使用
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
您已经在这样做了。但是然后说
使用这种方法,触摸屏幕上的任何位置都会使导航栏(和状态栏)重新出现并保持可见。用户交互导致标记被清除。清除标志后,如果您想再次隐藏条,则您的应用需要重置它们。请参阅Responding to UI Visibility Changes,以获取有关如何侦听UI可见性更改以使您的应用程序可以做出相应响应的讨论。
这意味着当用户选择选项菜单时,您将必须重置标志。还给出了示例代码here。