Switch from transparent status bar to Android color

advertisements

I'm working on Lollipop & I know how to color the status bar by setting this flag FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS & setting the color by getWindow().setStatusBarColor(color);

But I have a image & a transparent ActionBar & I want to show the image behind the action bar & when the users scrolls the ListView below the image the status bar should get fill with color as ActionBar

The problem is showing image behind the status bar & later after scrolling filling status bar with color. I don't know how this effect can be achieved.

Any help would be appreciated


first of all you have to add TranslucentActionBar Style on your style.xml

    <style name="AppTheme.TranslucentActionBar">
    <item name="android:actionBarStyle">@style/Widget.ActionBar.Transparent</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="actionBarStyle">@style/Widget.ActionBar.Transparent</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowContentOverlay">@null</item>
   <!--  <item name="windowContentOverlay">@null</item> -->
</style>

Add this method in your class.

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}

Next, Add this in OnCreate method before setContentView()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
        }

then status bar will be overlay your activity.

add scroll listener and add set status bar alpha method like this.

getWindow().setStatusBarColor(Color.argb(alpha, 253, 152, 0));