Douglas Fornaro
Douglas Fornaro

Reputation: 2037

How to update the status bar color also make it transparent on drawer

I set the action bar color dinamically.

I'm trying this way:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.8f;
    color = Color.HSVToColor(hsv);
    getWindow().setStatusBarColor(color)
}

How you can see, I'm setting the action bar color and making the color darker to be setted on status bar. I don't know if this is the right way but until now it's working.

The problem is when I open the drawer the color isn't being transparent. How can I do it here?

Upvotes: 1

Views: 426

Answers (1)

Anton Tarasov
Anton Tarasov

Reputation: 546

You can do this by using the following:

In Activity, which holds the toolbar, add to onCreate():

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    int flag = getWindow().getDecorView().getSystemUiVisibility();
    getWindow().getDecorView().setSystemUiVisibility(flag | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

In styles-v21:

<item name="android:windowTranslucentStatus">false</item>
<item name="android:statusBarColor">#30000000</item> <!-- This is gonna make status bar darker by 20% -->

This should be enough for it to work.

Upvotes: 1

Related Questions