How to hide navigation bar in Android App Code

user3041263 picture user3041263 · Dec 19, 2013 · Viewed 12.6k times · Source

I added this code to my app ;

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

But The code forces me to add "SuppressLint NewApi to MainActivity".Also there is an error about "View.SYSTEM_UI_FLAG_FULLSCREEN".Code says "CHANGE TO...." so what I must do I don't know.

Please help me.Thanks a lot.

Answer

Rahul Raina picture Rahul Raina · Apr 28, 2017

Here is simple code to hide Navigation bar in Activity. It is working.

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);