1
votes

I recently added the following code to my app to remove the navigation bar (soft buttons) from some phones. This caused some resizing issues with my app so getting rid of the navigation bar was ideal.

getWindow().requestFeature(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

See more: https://developer.android.com/training/system-ui/navigation.html

This does exactly what I wanted. The soft buttons are no longer present on devices such as the Nexus 5. However, this caused the side effect of disabling and touch or gestures until there is at least one touch event first. For example, I have some buttons on the home screen. With the above code, tapping on the button the first time does nothing. From the second time onwards, the app behaves like normal. My app also uses a viewpager, and swiping to other tabs or selecting another tab from the action bar also has no effect until I tap somewhere on the screen first.

Obviously, this behaviour is not wanted. When the user opens the app and selects one of the buttons, they expect the button to be clicked. Instead, they'd have to tap the button twice (and then everything works fine from that point on).

I'm testing this on the Samsung Galaxy S3 (which does not have the navigation bar along the bottom) and the Nexus 5 (which does have the navigation bar along the bottom).

Edit: Further research - Hiding the navigation bar is only temporary. The navigation bar is requesting focus for the first touch event, since the navigation bar is meant to pop back up as soon as there is any kind of ui event. So even on the Galaxy S3, which has no navigation bar in the first place, the touch event is being sucked up by the navigation bar. For devices that really do have a navigation bar, the bar will reappear on every interaction and you must tell the device to hide it again. As far as I can tell, there is no way to permanently hide the navigation bar.

My next question is to find out how it is possible to query the device to see if there is a navigation bar. If I know that the device does not have the navigation bar, then there is no need to try to hide it and have the OS absorb the first touch event.

1
I am having the same problem. Did you fix this?marimaf

1 Answers

2
votes

SYSTEM_UI_FLAG_HIDE_NAVIGATION is designed for passive activities like watching videos and maybe reading books. For your purposes, immersive mode is a better choice. https://developer.android.com/training/system-ui/immersive.html

More specifically you may want to add the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag together with SYSTEM_UI_FLAG_HIDE_NAVIGATION, so that the navigation bar is hidden and will stay hidden until user swipes from top or bottom.

Note that a "reminder bubble" will appear the first time a user enters this mode in your app.