Hide system bars for immersive mode

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(window.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().

Specify behavior of hidden system bars

Use WindowInsetsControllerCompat.setSystemBarsBehavior() to specify how hidden system bars behave when the user interacts with them.