Search code examples
androidandroid-layoutstatusbar

Fixed Status bar and hidden Navigation bar


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.


Solution

  • 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.sstatic.net/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);