Enable fullscreen mode

Some content is best experienced fullscreen, like videos, games, image galleries, books, and
slides in a presentation. This page shows how you can engage users more deeply with content in
fullscreen and protect users from exiting the app accidentally.

You might be tempted to enable fullscreen mode just to maximize screen space for your app.
But be mindful of how often users jump in and out of apps to check
notifications, do impromptu searches, and more. Using fullscreen causes
users to lose easy access to system navigation, so you should use fullscreen 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 exerience
for images, videos, and books).

Fullscreen options

Android offers three options to making your app fullscreen: Lean Back, Immersive, and
Immersive Sticky. In all three
approaches, the system bars are hidden and your activity continues to receive all touch events.
The difference between them is how the user can bring
the system bars back into view.

The following is a description of each of the different options. For example code, jump down to
Enable fullscreen mode.

Lean back

The lean back mode is for fullscreen experiences in which users won't be
interacting heavily with the screen, such as while
watching a video.

When users want to bring back the system bars, they simply tap the screen anywhere.

Immersive

The immersive mode is intended for apps in which the user will be
heavily interacting with the screen.
Examples are games, viewing images in a gallery, or reading paginated
content, like a book or slides in a presentation.

When users need to bring back the system bars,
they swipe from any edge where a system bar is hidden. By requiring this more
deliberate gesture, the user's engagement with your app won't be
interrupted by accidental touches and swipes.

If your app has its own controls that aren't needed when a user is immersed
in content, make them disappear and reappear in sync with the system bars.
This recommendation also applies to any app-specific gestures you might have for hiding
and showing app controls. For example, if touching anywhere on the screen
toggles the appearance of a toolbar or a palette, then it should also
toggle the appearance of system bars.

Sticky immersive

In the regular immersive mode, any time a user swipes from an edge,
the system takes care of revealing the system bars—your app
won't even be aware that the gesture occurred. So if the user might actually need to swipe
from the edge of the screen as part of the primary app experience—such as when playing
a game that requires lots of swiping or using a drawing app—you should instead enable
the "sticky" immersive mode.

While in sticky immersive mode, if the user swipes from an edge with a system bar, system bars
appear but they're semi-transparent, and the touch gesture is passed to your app so it app can
also respond to the gesture.

For example, in a drawing app that uses this approach, if the user wants to
draw a line that begins at the very edge of the screen, swiping from the edge
reveals the system bars and also starts drawing a line that begins at the
very edge. 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.

With stick immersive, you cannot receive a callback when the system UI visibility changes. So
if you want the auto-hiding behavior of sticky immersive mode, but still want to know when
the system UI re-appears in order to show your own UI controls as well, use the regular
IMMERSIVE flag and use
Handler.postDelayed() or something similar to
re-enter immersive mode after a few seconds.

The following code shows how to hide and show the status and navigation bars in your activity,
without resizing your layout in response to the changing screen space:

Kotlin

override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI()
}
private fun hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private fun showSystemUI() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
}

You might also want to implement the following to provide a better user
experience:

To provide a seamless transition between states,
keep the visibility of all UI controls in sync with the system bars. Once the app enters
immersive mode, any UI controls should also hide along with the system bars, and then also reappear
when the system UI reappears. To do so, implement
View.OnSystemUiVisibilityChangeListener to receive callbacks, as described in
Respond to UI Visibility Changes.

Implement onWindowFocusChanged().
If you gain window focus, you may want to re-hide the system bars.
If you lose window focus, for example due to a dialog or pop up menu showing above your app,
you'll probably want to cancel any pending "hide" operations you previously scheduled
with Handler.postDelayed() or something similar.

Implement a GestureDetector that detects
onSingleTapUp(MotionEvent), to allow users to
manually toggle the visibility of the system bars by touching your content.
Simple click listeners aren't the best solution for this because they get triggered even
if the user drags a finger across the screen (assuming the click target takes up the whole
screen).

Note:
When you use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag, a swipe
causes the system UI to temporarily appear in a semi-transparent state, but no flags are cleared
and your system UI visibility change listeners are not triggered.

Additional sample code

To see more code using different fullscreen modes, see the following samples: