Small guide: how to support immersive mode under Android 4.4+

In Android 4.4 version we have new Immersive mode which allows to make system bars translucent and extend application area to fit all screen. This looks great as it gives more space to application in terms of usability and it creates more stylish look if application design is done accordingly.

I added support of immersive mode to TripBudget. And there were some unexpected troubles on the way so i decided to write some kind of guide here.

Note: I talk here about immersive mode where bottom navigation bar is hidden – using SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag. This guide is aimed to gather and solve all problems which prevent sticky mode to work properly.

There are several approaches how to enable the mode itself – i like programmatic way without any xml scheme modifications. We need just set some properties of window to enable translucent system bars (status bar and bottom navigation bar).

In perfect world that would be enough, but the main problem raises when we need to keep immersive mode during application life cycle. Solution suggested by Google is pretty simple – you just handle onSystemUiVisibilityChange / onWindowFocusChanged events. Like this:

Im sorry that i cant put full example here as its part of my complex app. If you just want full screen behaviour use WindowManager.LayoutParams.FLAG_FULLSCREEN flag. Also see WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN flag.

Vivek

What is the default value for isApplicationInImmersiveMode ? And where it is changed ?

Thanks for this information. Quick question. If one develops and app using this new immersive mode function / feature then what would happen if someone tries to install that app / .apk on a pre Android 4.4 device. Is there a way for the code to work on pre and post 4.4 devices.

I say this as I made an app recently which worked on old and new devices (4.2, 4.4 and 5.0) but then after putting Immersive mode onto the app it now will only install on 4.4 and above devices.

Victor Laskin

No need to set 4.4 limitation. You can use areTranslucentBarsAvailable() function to detect if your device supports immersive mode. And if it does not, you just dont call unimplemented api and everything still works. But you have to take into account that application’s content should be aware that there can be no overlay bars on some devices.