How do I maintain the Immersive Mode in Dialogs?

后端 未结 7 696
醉酒成梦
醉酒成梦 2020-11-28 01:14

How do I maintain the new Immersive Mode when my activities display a custom Dialog?

I am using the code below to maintain the Immersive Mode in Dialogs, but with th

7条回答
  •  囚心锁ツ
    2020-11-28 01:46

    This also works over ride the onDismiss method of your dialog fragment . And within that method call the method of the activity to which it is attached to again set the full screen flags .

    @Override
        public void onDismiss(DialogInterface dialog) {
            super.onDismiss(dialog);
            Logger.e(TAG, "onDismiss");
            Log.e("CallBack", "CallBack");
            if (getActivity() != null &&
                    getActivity() instanceof LiveStreamingActivity) {
                ((YourActivity) getActivity()).hideSystemUI();
            }
        }
    

    And in your activity add this method :

    public void hideSystemUI() {
            // Set the IMMERSIVE flag.
            // Set the content to appear under the system bars so that the content
            // doesn't resize when the system bars hide and show.
            getWindow().getDecorView().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 // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    

提交回复
热议问题