BArtWell
BArtWell

Reputation: 4044

Status bar transparency doesn't work

I am trying to make status bar transparent in my application using this code:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(Color.TRANSPARENT);

But it doesn't work. Status bar just change a color and became grey, not transparent. Where is my mistake? How to make status bar transparent?

Upvotes: 8

Views: 2773

Answers (1)

Ismael Di Vita
Ismael Di Vita

Reputation: 1836

Try this in your styles.xml(v21)

<name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>

Update

You can achieve the same effect programatically on KitKat and afterwards by setting this Window flag

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

If you set a background resource (like a color or a picture) to your layout, you will see the color or picture "below" the status bar.

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/primary_dark</item>

Source

Upvotes: 5

Related Questions