5

Is it possible to hide the navbar without hiding the status bar?

I've tried this in my styles's xml

  <item name="android:windowFullscreen">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>

and I hide de navbar like this in the activity

  val decorView = window.decorView
        val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        decorView.systemUiVisibility = uiOptions

Thank you!!

Edit:

   fun hideNavigationStatusBar(activity: Activity) {
        activity.window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
        val decorView = activity.window.decorView
        val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        decorView.systemUiVisibility = uiOptions
    }

    fun translucidNavigationBar(activity: Activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            val w = activity.window
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
        }
    }

I can hide status and navigation bar with the first method and keep the status with a translucent navigation with the second, but still I can't reach to keep the status and completely hide the navigation bar.

Pablo R.
  • 711
  • 2
  • 10
  • 31

2 Answers2

1

You can use this method:

private void setTransparentStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
}
HedeH
  • 2,869
  • 16
  • 25
  • This makes my nav bar translucent but the status bar is hidden anyway – Pablo R. Jul 09 '18 at 13:04
  • This method doesn't hide the status bar, please remove the part in your code that does. I believe it's this one: `View.SYSTEM_UI_FLAG_FULLSCREEN` – HedeH Jul 09 '18 at 13:13
1

The easiest way to solve this is in two parts, removing the navbar and then making the status bar transparent.

1 - Removing the navbar

To remove the navbar, create a new style on the styles.xml file under the values folder that inherits from Theme.AppCompat.Light.NoActionBar.

https://i.stack.imgur.com/UdMLQ.png

Then on the manifest.xml file change the theme of the Activity to your custom style.

Edited manifest

With this the navbar will be removed, but the status bar will still be grayed out.

2 - Making the status bar transparent

You can follow this tutorial to make the status bar transparent: Transparent Status Bar

Or just add the following to the onCreate method of your Activity:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

enter image description here

With this you can expect an App style similar to the one in the next picture:

enter image description here

3 - Removing the status bar completely

To hide the status bar completely, add this on your onCreate method:

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

You can read more on this at Hiding the status bar

Result:

enter image description here

4 - Removing the navigation Bar

You can find a solution to this at the Android Developer site Hiding the navigation bar

Basically just add this to your onCreate:

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
arkandas
  • 110
  • 6
  • Thank you so much, but there is any way to completely hide de navigation bar? – Pablo R. Jul 09 '18 at 15:44
  • 1
    The navigation bar is hidden when I enter into the screen but when I touch any part of it, navbar appears again. – Pablo R. Jul 10 '18 at 07:57
  • Hi arkandas I think you wrote almost all the options xD, but again Is it possible to keep the status and hide the navbar? with your second option navbar is hidden until I touch the screen. Anyway thank you so much!! – Pablo R. Jul 10 '18 at 08:13
  • Sorry, I think I'm not understanding exactly what you want to achieve. Could you maybe upload a picture reflecting the end result you hope to get? – arkandas Jul 10 '18 at 08:40