Android ActionBar Set setColor(ActionBarActivity activity, int colorRes, Drawable oldBackground, Drawable.Callback drawableCallback)

Here you can find the source of setColor(ActionBarActivity activity, int colorRes, Drawable oldBackground, Drawable.Callback drawableCallback)

Description

set Color

License

Open Source License

Declaration

public static Drawable setColor(ActionBarActivity activity,
            int colorRes, Drawable oldBackground,
            Drawable.Callback drawableCallback) 

Method Source Code

//License from project: Open Source License 

import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;

public class Main{
    public static Drawable setColor(ActionBarActivity activity,
            int colorRes, Drawable oldBackground,
            Drawable.Callback drawableCallback) {
        Drawable colorDrawable = new ColorDrawable(colorRes);
        if (oldBackground == null) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
                colorDrawable.setCallback(drawableCallback);
            else//from   w w  w . j ava2  s  .  c  o  m
                activity.getSupportActionBar().setBackgroundDrawable(
                        colorDrawable);
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                    oldBackground, colorDrawable });
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
                td.setCallback(drawableCallback);
            else
                activity.getSupportActionBar().setBackgroundDrawable(td);
            td.startTransition(200);
        }
        return colorDrawable;
    }
}

Related

  1. getActionBarSize(Context context)