下面列出了怎么用android.animation.ArgbEvaluator的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected Animator createEngineAnimator(View view) {
ArgbEvaluator argbEvaluator = new ArgbEvaluator();//渐变色计算类
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f,1f);
valueAnimator.setDuration(850);
// valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mColorValue = (float) animation.getAnimatedValue();
mCurrentColor = (int) (argbEvaluator.evaluate(mColorValue, TRANSPARENT_COLOR, mPressedColor));
view.invalidate();
}
});
return valueAnimator;
}
public void startAnimation() {
final ImageView imageView = (ImageView) findViewById(R.id.image_view);
ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), RED,
BLUE);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
imageView.setBackgroundColor((Integer) animation
.getAnimatedValue());
}
});
anim.setDuration(10000);
anim.start();
}
@Override
protected Animator createExtinctAnimator(View view) {
ArgbEvaluator argbEvaluator = new ArgbEvaluator();//渐变色计算类
ValueAnimator valueAnimator;
if(mColorValue < 0.5f){
valueAnimator = ValueAnimator.ofFloat(mColorValue,0.8f,0.6f,0.4f,0.2f,0f);
}else{
valueAnimator = ValueAnimator.ofFloat(mColorValue,0f);
}
valueAnimator.setDuration(450);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mColorValue = (float) animation.getAnimatedValue();
mCurrentColor = (int) (argbEvaluator.evaluate(mColorValue, TRANSPARENT_COLOR, mNormalColor));
view.invalidate();
}
});
return valueAnimator;
}
private void updateColor(@NonNull ArgbEvaluator colorEvaluator) {
float fraction;
int colorFrom;
int colorTo;
if (colorIntermediate != -1) {
colorFrom = alpha <= 0f ? colorMore : colorIntermediate;
colorTo = alpha <= 0f ? colorIntermediate : colorLess;
fraction = alpha <= 0 ? (1 + alpha / 45f) : alpha / 45f;
} else {
colorFrom = colorMore;
colorTo = colorLess;
fraction = (alpha + 45f) / 90f;
}
color = (int) colorEvaluator.evaluate(fraction, colorFrom, colorTo);
paint.setColor(color);
}
/**
* Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip
* With a color transition animation
*
* @param color the final color
* @param duration the transition color animation duration
*/
void setColor(int color, int duration) {
final ValueAnimator colorAnim = ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setDuration(duration);
colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final int animatedValue = (Integer) animation.getAnimatedValue();
int colorAlpha = colorWithAlpha(animatedValue, lastPercent);
mHeader.headerBackground.setBackgroundColor(colorAlpha);
mHeader.statusBackground.setBackgroundColor(colorAlpha);
mHeader.toolbar.setBackgroundColor(colorAlpha);
mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha);
mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha);
//set the new color as MaterialViewPager's color
settings.color = animatedValue;
}
});
colorAnim.start();
}
@Override
public void onColorSelection(@NonNull ColorChooserDialog dialog, @ColorInt int color) {
int colorFrom = XposedApp.getColor(this);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, color);
colorAnimation.addUpdateListener(animator -> {
int color1 = (int) animator.getAnimatedValue();
toolbar.setBackgroundColor(color1);
int darkenColor = XposedApp.darkenColor(color1, getDarkenFactor());
getWindow().setStatusBarColor(darkenColor);
if (navBar != null && navBar.isChecked()) {
getWindow().setNavigationBarColor(darkenColor);
}
});
colorAnimation.setDuration(750);
colorAnimation.start();
if (!dialog.isAccentMode()) {
XposedApp.getPreferences().edit().putInt("colors", color).apply();
}
}
private void init() {
mEvaluator = new ArgbEvaluator();
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mCurrentColor = getColor(mProgress, mColors[mFromColorIndex],
mColors[mToColorIndex]);
postInvalidate();
mProgress += 0.1;
if (mProgress > 1.0) {
mFromColorIndex = mToColorIndex;
// Find a new color.
mToColorIndex++;
if (mToColorIndex >= mColors.length) {
mToColorIndex = 0;
}
}
mHandler.sendEmptyMessageDelayed(0, 100);
}
};
}
@Override
public void saveTheme(Integer themeId) {
SharedPreferences prefs = getAbstracContext().getSharedPreferences(
Constants.SHARE_PREFS, Context.MODE_PRIVATE);
prefs.edit().putInt(Constants.THEME, themeId).apply();
setTheme(themeId);
int startColor = ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY);
TypedValue typedValue = new TypedValue();
TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
int endColor = a.getColor(0, 0);
a.recycle();
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor);
colorAnimation.setDuration(2000); // milliseconds
colorAnimation.addUpdateListener(animator -> binding.logo.setBackgroundColor((int) animator.getAnimatedValue()));
colorAnimation.start();
}
private void updateHeaderColor(int newBackgroundColor, int newTextColor) {
if (mCurrentColor != newBackgroundColor) {
if (colorAnimation != null && colorAnimation.isRunning()) {
colorAnimation.cancel();
}
if (headerLayout != null) {
final int DURATION = 200;
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mCurrentColor, newBackgroundColor).setDuration(DURATION);
mCurrentColor = newBackgroundColor;
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
headerLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue());
}
});
colorAnimation.start();
for (int i = 0, size = headerTextViews.size(); i < size; i++) {
animateTextColorChange(newTextColor, DURATION, headerTextViews.get(i));
}
}
}
}
public void load(boolean anim) {
if (contentView == null)
return;
int duration = anim ? getResources().getInteger(R.integer.anim_speed) : 1;
progressWheel.setVisibility(VISIBLE);
if (contentView.getMeasuredHeight() == 0) {
AnimUtils.mesureView(contentView);
}
int buttonHeight = contentView.getMeasuredHeight() - contentView.getPaddingTop() - contentView.getPaddingBottom();
progressWheel.setCircleRadius(buttonHeight / 2);
progressWheel.animate().setDuration(duration).alpha(1);
progressWheel.spin();
if (contentView instanceof TextView) {
int color = ((TextView) contentView).getTextColors().getDefaultColor();
ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), color, Color.argb(0, Color.red(color), Color.green(color), Color.blue(color)));
textColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
((TextView) contentView).setTextColor((Integer) animator.getAnimatedValue());
}
});
textColorAnimator.setDuration(duration);
textColorAnimator.start();
}
animateToRadius(buttonHeight / 2, duration, new SimpleAnimatorListener());
}
private void runEnterAnimation() {
/* Animate color transitions */
ObjectAnimator background = ObjectAnimator.ofObject(container, "backgroundColor",
new ArgbEvaluator(), green,
pink).setDuration(500);
background.start();
/* Translate text1 to its current (R.layout.fragment_transitions_example) position */
text1.animate().setDuration(500)
.translationX(0)
.translationY(0)
.setInterpolator(sDecelerator).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
getActivity().getWindow().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.pink)));
}
});
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.invalidRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.getBackground().setColorFilter((int) animation.getAnimatedValue(), PorterDuff.Mode.SRC_ATOP);
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(getActivity(), R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.invalidRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.getBackground().setColorFilter((int) animation.getAnimatedValue(), PorterDuff.Mode.SRC_ATOP);
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(this, R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.invalidRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.getBackground().setColorFilter((int) animation.getAnimatedValue(), PorterDuff.Mode.SRC_ATOP);
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(getActivity(), R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
@Override
public void onDrawState(final EmptyStateRecyclerView rv, Canvas canvas) {
canvas.drawText(title,
(rv.getMeasuredWidth() >> 1),
(rv.getMeasuredHeight() >> 1),
textPaint);
// Setup animator, if necessary
if (anim == null) {
this.anim = ObjectAnimator.ofObject(textPaint, "color", new ArgbEvaluator(),
Color.parseColor("#E0E0E0"), Color.parseColor("#BDBDBD"), Color.parseColor("#9E9E9E"));
this.anim.setDuration(900);
this.anim.setRepeatMode(ValueAnimator.REVERSE);
this.anim.setRepeatCount(ValueAnimator.INFINITE);
this.anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
rv.invalidate();
}
});
this.anim.start();
}
}
@Override
public final void onDrawState(final EmptyStateRecyclerView rv, Canvas canvas) {
final int width = rv.getMeasuredWidth();
final int height = rv.getMeasuredHeight();
// Draw all of our content items
renderContent(numberOfContentItems, width, height, canvas, contentPaint);
// Setup and start animation, if possible
if (animateContentItems) {
if (anim == null) {
this.anim = ObjectAnimator.ofObject(contentPaint, "color", new ArgbEvaluator(),
Color.parseColor("#E0E0E0"), Color.parseColor("#BDBDBD"), Color.parseColor("#9E9E9E"));
onInterceptAnimatorCreation(anim);
this.anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
rv.invalidate();
}
});
this.anim.start();
}
}
}
@Override
public final void onDrawState(final EmptyStateRecyclerView rv, Canvas canvas) {
final int width = rv.getMeasuredWidth();
final int height = rv.getMeasuredHeight();
// Draw all of our content items
renderContent(numberOfContentItems, width, height, canvas, contentPaint);
// Setup and start animation, if possible
if (animateContentItems) {
if (anim == null) {
this.anim = ObjectAnimator.ofObject(contentPaint, "color", new ArgbEvaluator(),
Color.parseColor("#E0E0E0"), Color.parseColor("#BDBDBD"), Color.parseColor("#9E9E9E"));
onInterceptAnimatorCreation(anim);
this.anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
rv.invalidate();
}
});
this.anim.start();
}
}
}
private void animateClose(final View v) {
int colorFrom = G.context.getResources().getColor(R.color.black);
int colorTo = G.context.getResources().getColor(R.color.transparent);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(300); // milliseconds
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
v.setBackgroundColor((int) animator.getAnimatedValue());
}
});
colorAnimation.start();
}
public CubeReversalView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mBottomOutAnimation = new BottomOutAnimation();
mBottomOutAnimation.setDuration(DURATION);
mBottomOutAnimation.setFillAfter(true);
mBottomInAnimation = new BottomInAnimation();
mBottomInAnimation.setDuration(DURATION);
mBottomInAnimation.setFillAfter(true);
mTopOutAnimation = new TopOutAnimation();
mTopOutAnimation.setDuration(DURATION);
mTopOutAnimation.setFillAfter(true);
mTopInAnimation = new TopInAnimation();
mTopInAnimation.setDuration(DURATION);
mTopInAnimation.setFillAfter(true);
mArgbEvaluator = new ArgbEvaluator();
mBackgroundDrawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{0x00000000, 0x00000000, 0x00000000});
mForegroundDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{0x00000000, 0x00000000, 0x00000000});
}
private void startAnimation() {
final ImageView imageView = findViewById(R.id.image_view);
ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), RED,
BLUE);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
imageView.setBackgroundColor((Integer) animation
.getAnimatedValue());
}
});
anim.setDuration(10000);
anim.start();
}
private void startAnimation() {
float sunYStart = mSunView.getTop();
float sunYEnd = mSkyView.getHeight();
ObjectAnimator heightAnimator = ObjectAnimator
.ofFloat(mSunView, "y", sunYStart, sunYEnd)
.setDuration(3000);
heightAnimator.setInterpolator(new AccelerateInterpolator());
ObjectAnimator sunsetSkyAnimator = ObjectAnimator
.ofInt(mSkyView, "backgroundColor", mBlueSkyColor, mSunsetSkyColor)
.setDuration(3000);
sunsetSkyAnimator.setEvaluator(new ArgbEvaluator());
ObjectAnimator nightSkyAnimator = ObjectAnimator
.ofInt(mSkyView, "backgroundColor", mSunsetSkyColor, mNightSkyColor)
.setDuration(1500);
nightSkyAnimator.setEvaluator(new ArgbEvaluator());
AnimatorSet animatorSet = new AnimatorSet();
animatorSet
.play(heightAnimator)
.with(sunsetSkyAnimator)
.before(nightSkyAnimator);
animatorSet.start();
}
private static ValueAnimator colorChangeAnimation(TextView view, int from, int to) {
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), from, to);
colorAnimation.addUpdateListener(animation -> {
final Integer color = (Integer) animation.getAnimatedValue();
view.setTextColor(color);
});
colorAnimation.setDuration(300);
return colorAnimation;
}
private void hideRetry() {
if (retryAnim != null)
retryAnim.cancel();
retrying = false;
//bottomButtons.setVisibility(View.VISIBLE);
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
colorAnim.setEvaluator(new ArgbEvaluator());
}
AnimatorSet set = new AnimatorSet();
set.playTogether(
colorAnim,
ObjectAnimator.ofFloat(endBtnIcon, "rotation", -135, 0),
ObjectAnimator.ofFloat(endBtn, View.TRANSLATION_X, 0),
ObjectAnimator.ofFloat(cancelBtn, View.ALPHA, 0)//,
//ObjectAnimator.ofFloat(bottomButtons, View.ALPHA, 1)
);
set.setStartDelay(200);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
cancelBtn.setVisibility(View.GONE);
endBtn.setEnabled(true);
retryAnim = null;
}
});
retryAnim = set;
set.start();
}
private void init(Context context, AttributeSet attrs) {
setClickable(true);
mArgbEvaluator = new ArgbEvaluator();
final float density = context.getResources().getDisplayMetrics().density;
mBoardWidth = (int) (DEFAULT_BOARD_WIDTH * density + 0.5);
//TODO 更多自定义属性的获取,这里hardcode先,以后有需要在提取出来
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SwitchButton);
int checkRes = ta.getResourceId(R.styleable.SwitchButton_checkSrc, DEFAULT_CHECK_DRAWABLE_ID);
mCheckedDrawable = context.getResources().getDrawable(checkRes);
int uncheckRes = ta.getResourceId(R.styleable.SwitchButton_uncheckSrc, DEFAULT_UNCHECK_DRAWABLE_ID);
mUncheckDrawable = context.getResources().getDrawable(uncheckRes);
mBoardWidth = ta.getDimensionPixelOffset(R.styleable.SwitchButton_boardWidth, mBoardWidth);
mCheckRevealColor = ta.getColor(R.styleable.SwitchButton_checkRevealColor, DEFAULT_CHECK_REVEAL_COLOR);
mUnCheckRevealColor = ta.getColor(R.styleable.SwitchButton_uncheckRevealColor, -1);
ta.recycle();
}
//init paint
mBroadPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBroadPaint.setStyle(Paint.Style.STROKE);
mBroadPaint.setColor(mBoardColor);
mBroadPaint.setStrokeWidth(mBoardWidth);
mBroadPaint.setDither(true);
mCoverPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCoverPaint.setStyle(Paint.Style.FILL);
mCoverPaint.setColor(DEFAULT_DISABLE_COVER_COLOR);
mCoverPaint.setDither(true);
mRevealBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRevealBgPaint.setFilterBitmap(true);
mRevealBgPaint.setStyle(Paint.Style.FILL);
}
private void animate(View v) {
try {
ObjectAnimator backgroundColorAnimator = ObjectAnimator.ofObject(v, "backgroundColor", new ArgbEvaluator(), 0xFF666666, getSwatchColor());
backgroundColorAnimator.setDuration(500);
backgroundColorAnimator.start();
} catch (Exception e) {
// Some devices crash at runtime when using the ObjectAnimator
v.setBackgroundColor(getSwatchColor());
}
}
private static void startColorAnimation(int fromColor, int toColor,
final ColorUpdateListener listener) {
// credits: http://stackoverflow.com/a/14467625/504611
ValueAnimator colorAnimation = ValueAnimator
.ofObject(new ArgbEvaluator(), fromColor, toColor)
.setDuration(500);
colorAnimation.setInterpolator(new AccelerateInterpolator());
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
listener.onColorUpdate((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
}
private void hideRetry(){
if(retryAnim!=null)
retryAnim.cancel();
retrying=false;
//bottomButtons.setVisibility(View.VISIBLE);
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
colorAnim.setEvaluator(new ArgbEvaluator());
}
AnimatorSet set=new AnimatorSet();
set.playTogether(
colorAnim,
ObjectAnimator.ofFloat(endBtnIcon, "rotation", -135, 0),
ObjectAnimator.ofFloat(endBtn, "translationX", 0),
ObjectAnimator.ofFloat(cancelBtn, "alpha", 0)//,
//ObjectAnimator.ofFloat(bottomButtons, "alpha", 1)
);
set.setStartDelay(200);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter(){
@Override
public void onAnimationEnd(Animator animation){
cancelBtn.setVisibility(View.GONE);
endBtn.setEnabled(true);
retryAnim=null;
}
});
retryAnim=set;
set.start();
}
@Override
void setupColorAnimations() {
super.setupColorAnimations();
if (mBgBarColorAnimator == null) {
mBgBarColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), mBackgroundBarColor, mProvidedBgBarColor);
mBgBarColorAnimator.addUpdateListener(animation -> {
mProvidedBgBarColor = (int) animation.getAnimatedValue();
mBackgroundBarPaint.setColor(mProvidedBgBarColor);
});
mBgBarColorAnimator.setDuration(mAnimDuration);
}
}
private void dimBackgroundAsAnimation(final View view) {
Integer colorFrom = ContextCompat.getColor(this, android.R.color.transparent);
Integer colorTo = ContextCompat.getColor(this, R.color.black_semi_transparent);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
view.setBackgroundColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
}
public void animateStatusActionBar(int colorFrom,int colorTo){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(250); // milliseconds
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
getWindow().setStatusBarColor((int) animator.getAnimatedValue());
getSupportActionBar().setBackgroundDrawable(new ColorDrawable((int) animator.getAnimatedValue()));
}
});
colorAnimation.start();
}