How can I hide the navigation bar in my application?

I am developing an application for a specific (one) device (Android 4.4.2), on which it should be on the whole screen, in which the navigation and the user should not be able to exit this application. I found a way to hide the status bar this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); but I don’t know what to do with the navigation bar.

enter image description here

It would be ideal, of course, to destroy this panel altogether, as the author of this question did. But on my device I cannot find the SystemUI.apk file.

    2 answers 2

    In fact, it is described in some detail in the documentation. The state you need is called Immersive Mode - we flick here and study , you should be specifically interested in the flag: View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY , with a slight refinement, you need a small handler to intercept the surfacing of the navigation bar and immediately hide it, otherwise it will pop up again and again.

    If you need a specific code, then the piece is lying around here .

    Copy-paste code:

     private int currentApiVersion; @Override @SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentApiVersion = android.os.Build.VERSION.SDK_INT; final int flags = 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 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; // This work only for android 4.4+ if(currentApiVersion >= Build.VERSION_CODES.KITKAT) { getWindow().getDecorView().setSystemUiVisibility(flags); // Code below is to handle presses of Volume up or Volume down. // Without this, after pressing volume buttons, the navigation bar will // show up and won't hide final View decorView = getWindow().getDecorView(); decorView .setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(flags); } } }); } } @SuppressLint("NewApi") @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if(currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) { getWindow().getDecorView().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 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } 
    • Thank. Yes, I have already studied this moment. I was worried that this panel appears every time. I thought that there is a more secure way to not use a handler and not invoke this action over and over again. - GlWhitefoot
    • Barmaley , you could not advise on what it is better to hang up the handler, which will be getWindow().getDecorView().setSystemUiVisibility( ...? What is shown in the example is hung to change the focus, but still translucent appears from above or below panels. Hang up on tap of the main view of the layout? - GlWhitefoot
    • Yes, xs ... here you have to understand and experiment with a live device and IDE on hand. This task, IMHO, clearly goes beyond the telegraphic style of the forum - Barmaley
     View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); 

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