10

I'm looking to make my Android app fullscreen, but only showing the android navigation bar on a certain screen (my settings screen). I know that it is dangerous to hide the navigation bar permanently on a screen, but I want to know if this is possible. I have looked into rooting my device and using the Xposed framework.

Is there a way to programmatically disable the navigation bar, or "sticky mode", and re-enable later?

Edit: I've looked at the Android Immersive Mode but it seems like the navigation bar will still show if the user touches the edge. I want to remove any hint of the navigation bar until they go to my settings screen.

Jason
  • 445
  • 1
  • 6
  • 16

1 Answers1

7

Yes it is possible. Use the below code snippet to achieve the desired functionality.

// This snippet hides the system bars.
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
   View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

For more details refer the the below google documentation :

https://developer.android.com/training/system-ui/immersive.html

EDIT 1 : To hide it permanently may be you could try something like this (Hacky)

decorView.setOnSystemUiVisibilityChangeListener
                (new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {

                            hideSystemUI();


                    }
                });`
Arpit Ratan
  • 2,976
  • 1
  • 12
  • 20
  • 1
    Thanks for your reply. I was looking at this before I posted but my question with Immersive Mode was this line: "The user can reveal the system bars with an inward swipe along the region where the system bars normally appear". Wouldn't this override the hide()? I want to disable that until the user goes to my setting screen. – Jason Jul 07 '16 at 20:06
  • Yes it does, in fact user is shown a tutorial when he opens the immersive mode for the first time. Which tells him that swiping down will close the full screen mode. – Arpit Ratan Jul 07 '16 at 20:09
  • 1
    Right, and I don't want them to close the full screen mode *unless* they go to one of my other screens. That's what my real question is. I want to prevent user from accessing the navigation bar completely until they go to a certain screen. – Jason Jul 07 '16 at 20:19
  • 1
    Updated my answer but I think you couldn't achieve the desired functionality without root access. – Arpit Ratan Jul 07 '16 at 20:25
  • Thanks. Yeah, I was expecting that I'd be needing to root the device... – Jason Jul 07 '16 at 20:27
  • Sorry for the old post bump, but what you're asking should never ever ever **ever** be allowed without them specifically giving you access on a rooted device. What you're asking is how to hijack someone's phone – Sampson Crowley Jul 05 '19 at 05:58
  • Add once more flage SYSTEM_UI_FLAG_IMMERSIVE_STICKY so hide navigation bar after home time – Sameer Z. Jan 24 '20 at 13:36