Let's practice how to control the System UI by referring to the
Android documentation
👆👆
Download PPT : https://github.com/ggujangi/ggu.system.ui/files/4094927/System.UI.Visibility.ppt.pptx
- Dimming the System Bars
- Hiding the Status Bar
- Hiding the Navigation Bar
- Using Immersive Full-Screen Mode
- Available in Android 4.0 (API level 14) and higher
- You can dim the status and notification bars using the
SYSTEM_UI_FLAG_LOW_PROFILE
flag - As soon as the user touches the status or navigation bar, the flag is cleared
- Calling
setSystemUiVisibility()
withSYSTEM_UI_FLAG_VISIBLE
flag clears all flags - As soon as the user touches the status or navigation bar, the flag is cleared
View mDecorView = getActivity().getWindow().getDecorView();
int mOption = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mDecorView.setSystemUiVisibility(mOption);
// clear all flags
mDecorView.setSystemUiVisibility(SYSTEM_UI_FLAG_VISIBLE);
<application
...
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
...
</application>
-
- When you set
WindowManager
flags, the flags remain in effect unless your app clears them - You can use
FLAG_LAYOUT_IN_SCREEN
to set your activity layout to use the same screen area that's available when you've enabledFLAG_FULL_SCREEN
- When you set
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
-
- Calling
setSystemUiVisibility()
withSYSTEM_UI_FLAG_FULLSCREEN
flag hides the status bar
- Calling
View mDecorView = getActivity().getWindow().getDecorView();
int mOption = View.SYSTEM_UI_FLAG_FULLSCREEN;
mDecorView.setSystemUiVisibility(mOption);
-
- When the user reopens the activity,
onCreate()
won't get called, so if you want system UI changes to persist, set UI flags inonResume()
ofonWindowFocusChanged()
- When the user reopens the activity,
- Available in Android 4.1 (API level 16) and higher
- If you use
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
, the content will not be resized when the navigation bar is hidden and visible. SYSTEM_UI_FLAG_LAYOUT_STABLE
helps your app maintain a stable layout.android:fitsSystemWindows
adjusts the padding of the parentViewGroup
and if set to true the app's UI will not be covered by the system bar
- Calling
setSystemUiVisibility()
withSYSTEM_UI_FLAG_HIDE_NAVIGATION
flag hides the navigation bar - You can also hide the status bar by using the
SYSTEM_UI_FLAG_FULLSCREEN
flag together. This works the same asLean back
in Full screen Options
View mDecorView = getActivity().getWindow().getDecorView();
int mOption = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
// Hide both the navigation bar and the status bar
int bothOption = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
mDecorView.setSystemUiVisibility(mOption);
- Available in Android 4.1 (API level 16) and higher
- If you use
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
, the content will not be resized when the navigation bar is hidden and visible SYSTEM_UI_FLAG_LAYOUT_STABLE
helps your app maintain a stable layout
- The lean back mode is for fullscreen experiences in which users won't be interacting heavily with the screen
- For example, watching a video.
- When the user taps anywhere on the screen, the system bar appears
- Calling
setSystemUiVisibility()
withSYSTEM_UI_FLAG_FULLSCREEN
andSYSTEM_UI_FLAG_HIDE_NAVIGATION
- When the system bars re-appear, you can receive a callback to make other appropriate updates to your UI
View mDecorView = getActivity().getWindow().getDecorView();
int mOption = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
mDecorView.setSystemUiVisibility(mOption);
- The immersive mode is intended for apps in which user will be heavily interacting with the screen
- For example, games, viewing images in a gallery, or reading paginated content
- When user swipe from any edge where a system bar is hidden, the system bars appear
- Calling
setSystemUiVisibility()
withSYSTEM_UI_FLAG_IMMERSIVE
andSYSTEM_UI_FLAG_FULLSCREEN
,SYSTEM_UI_FLAG_HIDE_NAVIGATION
- When the system bars re-appear, you can receive a callback to make other appropriate updates to your UI
View mDecorView = getActivity().getWindow().getDecorView();
int mOption = View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mDecorView.setSystemUiVisibility(mOption);
- For example, drawing app, playing a game that requires lots of swiping
- When user swipe from any edge where a system bar is hidden, the system bars appear but they're semi-transparent
- The bars automatically disappear after a few seconds of no interaction or as soon as the user touches or gestures anywhere outside the system bars
- Calling
setSystemUiVisibility()
withSYSTEM_UI_FLAG_IMMERSIVE_STICKY
andSYSTEM_UI_FLAG_FULLSCREEN
,SYSTEM_UI_FLAG_HIDE_NAVIGATION
- With sticky immersive, You cannot receive a callback when the system UI visibility changes
View mDecorView = getActivity().getWindow().getDecorView();
int mOption = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mDecorView.setSystemUiVisibility(mOption);