Some content is best experienced fullscreen without any indicators on the status bar or the navigation bar. Some examples are videos, games, image galleries, books, and slides in a presentation. This is referred to as immersive mode. This page shows how you can engage users more deeply with content in fullscreen.
Be mindful of how often users jump in and out of apps to check notifications, conduct impromptu searches, or other actions. Because using immersive causes users to lose easy access to system navigation, use immersive mode only when the benefit to the user experience goes beyond simply receiving a little extra space (such as to avoid accidental exits during a game or delivering a valuable immersive experience for images, videos, and books).
Use WindowInsetsControllerCompat.hide()
to hide the system bars, and WindowInsetsController.show()
to bring them back.
The following snippet shows an example of hiding and showing system bars.
Kotlin
private fun hideSystemBars() { val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView) ?: return // Configure the behavior of the hidden system bars windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE // Hide both the status bar and the navigation bar windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) }
Java
private void hideSystemBars() { WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView()); if (windowInsetsController == null) { return; } // Configure the behavior of the hidden system bars windowInsetsController.setSystemBarsBehavior( WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE ); // Hide both the status bar and the navigation bar windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); }
Optionally, you can specify the type of system bars to hide, and also determine their behavior when a user interacts with them.
Specify which system bars to hide
To specify the type of system bars to hide, pass one of the following parameters
to WindowInsetsControllerCompat.hide()
.
Use
WindowInsetsCompat.Type.systemBars()
to hide both system bars.Use
WindowInsetsCompat.Type.statusBars()
to hide only the status bar.Use
WindowInsetsCompat.Type.navigationBars()
to hide only the navigation bar.
Specify behavior of hidden system bars
Use WindowInsetsControllerCompat.setSystemBarsBehavior()
to specify how hidden system bars behave when the user interacts with them.
Use
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
to reveal hidden system bars on any user interactions on the corresponding display.Use
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE
to reveal hidden system bars on any system gestures, such as swiping from the edge of the screen where the bar is hidden from.Use
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
to temporarily reveal hidden system bars with system gestures, such as swiping from the edge of the screen where the bar is hidden from. These transient system bars overlay your app’s content, may have some degree of transparency, and are automatically hidden after a short timeout.