user11826955
user11826955

Reputation:

How can I hide Navigation Bar without hiding the status bar

I am trying to hide the Bottom navigation bar only and not the status bar. Most of the code I am getting is hiding both the navigation bar and the status bar.

Upvotes: 0

Views: 2260

Answers (2)

Vivek Sasidharan
Vivek Sasidharan

Reputation: 1295

Try the below function. Owing to changes in Android R, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, setSystemUiVisibility etc are being deprecated. I have made the function to handle this scenario.

public void hideBottomNavigationBar() {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
         getWindow().setDecorFitsSystemWindows(false);
         WindowInsetsController controller = getWindow().getInsetsController();
         if(controller != null) {
           controller.hide(WindowInsets.Type.navigationBars());
           controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
         }
      } else {
         getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

      }
}

Another thing to note about using View.SYSTEM_UI_FLAG_HIDE_NAVIGATION from the docs:

There is a limitation: because navigation controls are so important, the least user interaction will cause them to reappear immediately. When this happens, both this flag and SYSTEM_UI_FLAG_FULLSCREEN will be cleared automatically, so that both elements reappear at the same time.

Inorder to work around this limitation you can set View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY as well like this:

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

But this only works SDK 19 onwards.

Upvotes: 1

yanyusanqian
yanyusanqian

Reputation: 120

View v = getWindow().getDecorView();  
int options = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION  
            | View.SYSTEM_UI_FLAG_FULLSCREEN;  
v.setSystemUiVisibility(options); 

Upvotes: 0

Related Questions