How to solve the issue of attribute animation ofArgb version restrictions, attribute animation ofargb version
Attribute animation ValueAnimator. ofArgb is incompatible when the Android version is earlier than 5.0, causing program crash. How can this problem be solved? This requires the knowledge of the User-Defined estimator.
if (Build.VERSION.SDK_INT < 21){ mGradientAnim = ValueAnimator.ofObject(new TextArgbEvaluator(), startColor, endColor); }else { mGradientAnim = ValueAnimator.ofArgb(startColor , endColor); }
Private class TextArgbEvaluator implements TypeEvaluator {// This code is the public Object evaluate (float fraction, Object startValue, Object endValue) {int startInt = (Integer) startValue derived from the source code; int startA = (startInt> 24) & 0xff; int startR = (startInt> 16) & 0xff; int startG = (startInt> 8) & 0xff; int startB = startInt & 0xff; int endInt = (Integer) endValue; int endA = (endInt> 24) & 0xff; int endR = (endInt> 16) & 0xff; int endG = (endInt> 8) & 0xff; int endB = endInt & 0xff; return (int) (startA + (int) (fraction * (endA-startA ))) <24) | (int) (startR + (int) (fraction * (endR-startR) <16) | (int) (startG + (int) (fraction * (endG-startG) <8) | (int) (startB + (int) (fraction * (endB-startB ))));}}