animate ActionBar To Color - Android User Interface

Android examples for User Interface:ActionBar Color

Description

animate ActionBar To Color

Demo Code


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.app.ActionBar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;

public class Main{
    public static void animActionBarToColor(final ActionBar actionBar,
            int fromColor, int toColor) {
        ValueAnimator colorAnimation = ValueAnimator.ofObject(
                new ArgbEvaluator(), fromColor, toColor);
        colorAnimation.setDuration(1000);
        colorAnimation//from  w  w w.j ava2  s  .c  om
                .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animator) {
                        int color = (Integer) animator.getAnimatedValue();
                        Drawable colorDrawable = new ColorDrawable(color);
                        actionBar.setBackgroundDrawable(colorDrawable);
                    }
                });
        colorAnimation.start();
    }
}

Related Tutorials