animate Action Bar from one color To another Color - Android android.view.animation

Android examples for android.view.animation:Color Animation

Description

animate Action Bar from one color To another Color

Demo Code

import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.app.ActionBar;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

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);/*from   w w  w  .jav  a 2  s .  co  m*/
    colorAnimation.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