Text color animation

前端 未结 8 1853
南旧
南旧 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:55

    You can use new Property Animation Api for color animation:

    Integer colorFrom = getResources().getColor(R.color.red);
    Integer colorTo = getResources().getColor(R.color.blue);
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.addUpdateListener(new AnimatorUpdateListener() {
    
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            textView.setTextColor((Integer)animator.getAnimatedValue());
        }
    
    });
    colorAnimation.start();
    

    For backward compatability with Android 2.x use Nine Old Androids library from Jake Wharton.

提交回复
热议问题