This is my question: I have an android app which allows users to go full screen for a better readability. The full screen fab toggle button is placed inside a fragment which actually contains the readings.
To make it dead simple:
- Main Activity contains Readings Fragment
- Readings Fragment contains a fab button to toggle full screen
To trigger the full screen I use this snippet:
this.fullScreenFab.setOnClickListener(v -> { WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes(); if (this.isFullScreen) { this.isFullScreen = false; ((AppCompatActivity) getActivity()).getSupportActionBar().show(); getActivity().getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } else { this.isFullScreen = true; ((AppCompatActivity) getActivity()).getSupportActionBar().hide(); getActivity().getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } getActivity().getWindow().setAttributes(attrs); });
Now, it works well, except that the status bar and action bar spaces keep showing. The activity goes FS (even Android warn me of this) but the space occupied by those two elements remain.
Full screen disabled:
Full screen enabled:
As you can see, the FS one has the top and bottom occupied, so the fragment does not go for a real full screen.
Fragment has the
android:fitsSystemWindows="true"
Send help please! Thanks in advance. Valerio
Advertisement
Answer
You should try using this flag as it is designed to remove status bar and navigation.
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
NOTE: You need to manually clear this while switching or closing fragment. Else this fullscreen will be applicable till the parent activity exists. To do so,
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Also, you can use FLAG_FULLSCREEN
. Using it will effectively set a transparent notification bar but the icons on the status bar will still show up.