How to hide navigation bar in Android app?

后端 未结 6 758
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 05:28

I was wondering how I could hide the navigation bar in an Android application?

I know how to hide it initially, but as soon as I touch the screen it pops back up. I

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 06:31

    Just put this method in your activity where you want to hide status bar and navigation bar in sticky mode.

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        //This is used to hide/show 'Status Bar' & 'System Bar'. Swip bar to get it as visible.
        View decorView = getWindow().getDecorView();
        if (hasFocus) {
            decorView.setSystemUiVisibility(
                    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);
        }
    }
    

提交回复
热议问题