如何在Android中按动作栏菜单时隐藏导航栏

时间:2015-05-27 17:08:13

标签: android android-actionbar hide navigationbar

我隐藏了导航栏(见下文)但是当我按下操作栏上的菜单按钮时,会立即显示导航栏。 我可以隐藏导航吗?吧永久吧?

@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);
}

1 个答案:

答案 0 :(得分:1)

看看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);

你已经这样做了。但后来它说了

  

使用此方法,触摸屏幕上的任何位置都会导致导航栏(和状态栏)重新出现并保持可见状态。用户交互导致标志被清除。清除标志后,如果要再次隐藏栏,则应用程序需要重置它们。有关如何监听UI可见性更改的讨论,请参阅Responding to UI Visibility Changes,以便您的应用可以做出相应的响应。

这意味着当用户选择选项菜单时,您必须重置标志。示例代码也是here