I want to hide navigation bar permanently in my activity(not whole system ui). now i'm using this piece of code
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
It hides the bar but when user touches the screen it showing again. is there is any way to hide it permanently until activity onStop()
;
Do this.
This works 100% and you can do same for lower API versions, even if it's a late answer I hope it will helps someone else.
If you want this to be permanent, just call
FullscreenCall()
inside youronResume()
method.Try this.
let me know if that helps... :)
Its a security issue: https://stackoverflow.com/a/12605313/1303691
therefore its not possible to hide the Navigation on a tablet permanently with one single call at the beginning of the view creation. It will be hidden, but it will pop up when touching the Screen. So just the second touch to your screen can cause a onClickEvent on your layout. Therefore you need to intercept this call, but i haven't managed it yet, i will update my answer when i found it out. Or do you now the answer already?
Snippets:
FullScreenFragment.java
HideNavigationBarComponent.java
This is for Android 4.4+
Try out immersive mode https://developer.android.com/training/system-ui/immersive.html
Fast snippet (for an Activity class):
If you have problems when you press Volume up or Volume down that your navigation bar show. I added code in
onCreate
see setOnSystemUiVisibilityChangeListenerHere is another related question:
Immersive mode navigation becomes sticky after volume press or minimise-restore
I think the blow code will help you, and add those code before setContentView()
Add those code behind setContentView() getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
It's my solution:
First, define boolean that indicate if navigation bar is visible or not.
Second create method that hide navigation bar.
By default, if you click to activity after hide navigation bar, navigation bar will be visible. So we got it's state if it visible we will hide it.
Now set OnClickListener to your view. I use a surfaceview so for me:
Also, we must call this method when activity is launched. Because we want hide it at the beginning.