Home > front end >  How can I make the status bar / navigation bar invisible on Android, while keeping the padding at th
How can I make the status bar / navigation bar invisible on Android, while keeping the padding at th

Time:04-29

I'm trying to create an 'immersive mode' in my app, where tapping a button simply hides the status bar (and nav bar, if possible.) But I specifically don't want the whole app to resize itself so that the content moves up to fill the space where the status bar used to be -- I just want that top part of the screen to be filled with the same background colour it had before. Ideally from the user's point of view, the status bar notification icons / time / battery / etc. icons would just fade in and out. How can I achieve this?

The effect I'm looking for is basically what the Spotify app does on the Now Playing screen when the song has a 'Canvas' (the looping video that plays along with a song) -- tapping the background causing the Now playing UI to fade out, along with the status bar. So it must be possible!

Additionally, if the phone has a notch of some sort, I don't want the status bar to become completely black, as happens with some approaches to this I've seen.

CodePudding user response:

Here's the doc for the status bar and the doc for the navigation bar

I think what you are looking for is something like this :

View decorView = getWindow().getDecorView();
// Hide the status bar and navigation bar
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();

CodePudding user response:

You can transparent the status bar

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>
  • Related