Search code examples
androidandroid-statusbar

Display only status bar in android?


I want the app to show only the status bar and have the navigation bar in IMMERSIVE_STICKY mode. Tried a lot of things but somehow the nav bar stays and the status bar is hidden. Can the material theme be messing up with the full screen functionalities?

Tried other related question to the same problem but they address the problem in forms of hacks and also the API is version is older for the solutions. Here is my theme attribute and related setup code:

<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">

        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>```

Solution

  • According to the docs here, you need to use SYSTEM_UI_FLAG_HIDE_NAVIGATION in order to hide the bottom nav bar. They also pass the SYSTEM_UI_FLAG_FULLSCREEN flag since it is good practice to also hide the status bar when the nav bar is hidden.

    View decorView = getWindow().getDecorView();
    // Hide both the navigation bar and the status bar.
    // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
    // a general rule, you should design your app to hide the status bar whenever you
    // hide the navigation bar.
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    

    If I interpreted the question correctly, your requirement is NOT to hide the status bar, and hiding the nav bar. So, you should not be passing the fullscreen flag anywhere. Remove it from the above snippet, and also remove android:windowFullscreen from your theme. This should make the status bar appear as usual.

    So your actual uiOptions would be

    int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    

    Note: As mentioned in the docs, IMMERSIVE_STICKY only ensures that any touch event/gesture in the nav bar region is also transmitted to the app. It will still display a translucent nav bar if the user swipes there. As mentioned in other answers, it should be impossible to completely get it removed without some form of root access.


    Edit: I initially tested this with AppCompatActivity and the default Theme.AppCompat.Light.NoActionBar theme. Also tested out with OP's android:Theme.Material.Light.NoActionBar (which requires use of Activity instead of AppCompatActivity). Both of them worked.