20

Is is possible to force an app to always show to navigation bar in an Android app? On Samsung Galaxy S8 it is possible for the user to hide the navbar during "runtime" - which cause some unexpected behaviours in the app (if you are interested; I tried to add a setOnSystemUiVisibilityChangeListener and redraw, invalidate, requestLayout and forceLayout on the view with no luck. Restarting the activity is not applicable as the app is a single-activity-app. I've also looked into WindowInsets with no luck there neither.).

Therefor, I just want to avoid the problem by not allowing the user to remove the navbar. All the resources I can find online is for hiding the navbar. Does anybody how any suggestions on how to make it stay?

Dambakk
  • 595
  • 4
  • 20
  • 1
    Any luck on this? That nav bar for the s8 is messing up a lot of people's apps. Mine included. Would be nice to force it to either always be turned off or turned on without the user being able to toggle it on their own. – portfoliobuilder Sep 28 '17 at 22:16
  • No, unfortunately not... I agree! – Dambakk Sep 30 '17 at 02:26
  • 2
    I made progress on this Christopher. I figured out how to disable the toggling, but that does not mean the user is unable to display the nav bar. They can swipe it up, but it will not pin. Additionally, it looks like if your UI is getting messed up, the only solution is to add listeners and readjust (measure) the views and position things accordingly. The reason this is so troublesome for my app is because I use a lot of animations that rely on the y-cord. That y-cord needed to be dynamic depending upon if the nav bar was present or not. – portfoliobuilder Oct 03 '17 at 19:37
  • Ooo, nice! To make it not stick is a perfectly good solution! Do you mind explaining what you did? – Dambakk Oct 04 '17 at 21:35
  • Christopher look at this post here. The DecorView's systemUiVisibility options can be tailored to disable the ability to pin the nav bar. It acts similar to when the virtual keyboard is up and the pin option will not display. https://stackoverflow.com/questions/38254127/programmatically-enable-disable-immersive-mode – portfoliobuilder Oct 05 '17 at 00:15
  • I found dialog mode can hide the pin or unpin icon, and Alipay & Wechat they did it. – drakeet Jan 29 '18 at 03:51

2 Answers2

1

I am not much sure about Samsung S8, but I had worked on Samsung S7. I had used lean back mode setSystemUiVisibility() and passed these two flags

1.SYSTEM_UI_FLAG_FULLSCREEN
2.SYSTEM_UI_FLAG_HIDE_NAVIGATION
Also for enabling immersive mode, I had used SYSTEM_UI_FLAG_IMMERSIVE in conjunction.

It was referenced from visibility & immersive.

Correct me if I am wrong or I didn't understand the question.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Denny Mathew
  • 842
  • 3
  • 13
  • 31
0

This worked for me:

        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Viktor Jovanovski
  • 1,513
  • 10
  • 26