8

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?

BArtWell
  • 4,422
  • 8
  • 61
  • 101
  • You can maybe check one of my previous answers: http://stackoverflow.com/a/33986302/3426717 – Andrei Nov 29 '15 at 18:34

2 Answers2

5

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

Community
  • 1
  • 1
Ismael Di Vita
  • 1,766
  • 1
  • 18
  • 34
2

try calling this from onCreate:

getWindow().getDecorView().setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

getWindow().setStatusBarColor(Color.TRANSPARENT);
prat
  • 795
  • 5
  • 14