应用程序运行时以编程方式隐藏导航栏

时间:2014-08-19 19:12:34

标签: navigationbar android

我正在开发一个带有webview布局的安卓游戏。我想在用户玩游戏时隐藏导航栏。我找到了一些解决方案但是当我触摸屏幕时,导航栏会显示出来。

我做错了什么?这是我的非工作解决方案:

 int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LOW_PROFILE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

        getWindow().getDecorView().setSystemUiVisibility(mUIFlag);

1 个答案:

答案 0 :(得分:1)

您需要使用以下代码重新重置标志:

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
           decorView.setSystemUiVisibility(mUIFlag);
        } else {
            // TODO: The system bars are NOT visible. Make any desired
            // adjustments to your UI, such as hiding the action bar or
            // other navigational controls.
        }
    }
});

另外,请阅读this页面以了解如何处理您的方案