During the port, I came across one simple yet interesting problem -- Need to make the game UI truly full screen.
A lot of the Android devices have software navigation buttons at the bottom of their screens.
|Android System Navigation Buttons|
Ideal experience would be to hide System navigation buttons at all times, but have some gesture to bring them back for a short duration when user needs them.
Android 4.4 (API Level 19) natively supports this functionality using the flag "SYSTEM_UI_FLAG_IMMERSIVE_STICKY". This mode is called the immersive full screen mode. When immersive full-screen mode is enabled, game continues to receive all touch events. The user can reveal the system bars with an inward swipe along the region where the system bars normally appear. System bars will automatically hide again after a few moments. Perfect isn't it!
Usually setting this flag is enough to achieve the desired functionality, however in certain edges cases we need to do some additional work. For example if you have a text field which accepts user input, once the on screen keyboard is dismissed the system navigation bars seem to stick around and do not hide until you kill the app and open it again.
In this post we are going to see how exactly to handle all situations so that the immersive full screen mode will always stick around for the app.
How Do They Do It!
What we need to do is basically setup SystemUiVisibilityChangeListener and FocusChangeListener and hide the system status bars in the callbacks.
Here is the sample code on how to do it.
That's it. Once you run this Activity you should see that the game launches into immersive full-screen mode and remains in that mode!