Animate change of view background color on Android

前端 未结 16 1013
孤街浪徒
孤街浪徒 2020-11-22 13:23

How do you animate the change of background color of a view on Android?

For example:

I have a view with a red background color. The background color of the

16条回答
  •  借酒劲吻你
    2020-11-22 14:15

    You can use ArgbEvaluatorCompat class above API 11.

    implementation 'com.google.android.material:material:1.0.0' 
    
    
    ValueAnimator colorAnim = ValueAnimator.ofObject(new ArgbEvaluatorCompat(), startColor, endColor);
    colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mTargetColor = (int) animation.getAnimatedValue();
            }
        });
    colorAnimation.start();
    

提交回复
热议问题