Text color animation

前端 未结 8 1856
南旧
南旧 2020-12-14 10:09

Is there a way to animate a text color change (from anycolor to white)?

The only variant I came up with, is placing two textviews (with the same text) in one place,

8条回答
  •  一个人的身影
    2020-12-14 10:48

    best way use ValueAnimator and ColorUtils.blendARGB

     ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
     valueAnimator.setDuration(325);
     valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
    
                  float fractionAnim = (float) valueAnimator.getAnimatedValue();
    
                  textView.setTextColor(ColorUtils.blendARGB(Color.parseColor("#FFFFFF")
                                        , Color.parseColor("#000000")
                                        , fractionAnim));
            }
    });
    valueAnimator.start();
    

提交回复
热议问题