Android KitKat Immersive Mode使用

写了一个方法,在onCreate和onResume中调用即可,4.4以上可用。

private void openImmersiveMode() {
        if (android.os.Build.VERSION.SDK_INT > 18) {
            Window window = getWindow();
            this.getWindow()
                    .getDecorView()
                    .setSystemUiVisibility(
                            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        }

    }

如果是cocos2dx游戏工程的话最好加入如下代码

@Override
    public void onWindowFocusChanged(boolean hasFocus) {
        // TODO Auto-generated method stub
        if (hasFocus) {
            Log.i("AppActivity",
                    "onWindowFocusChanged->hasFocus="
                            + String.valueOf(hasFocus));
            openImmersiveMode();
        }
        super.onWindowFocusChanged(hasFocus);

    }

 

posted on 2015-06-18 14:24  益达的博客  阅读(277)  评论(0编辑  收藏  举报

导航