Code example for ValueAnimator

Methods: addListener, addUpdateListener

0
        if (v.getBackground() instanceof BackgroundAlphaColorDrawable) { 
            final BackgroundAlphaColorDrawable bg = (BackgroundAlphaColorDrawable) v 
                    .getBackground(); 
            anim = ValueAnimator.ofObject(new ArgbEvaluator(), info.color, 
                    BackgroundAlphaColorDrawable.applyAlphaToColor(bg.getBgColor(), alpha)); 
            anim.addUpdateListener(new AnimatorUpdateListener() { 
                @Override 
                public void onAnimationUpdate(ValueAnimator animation) { 
                    info.color = (Integer) animation.getAnimatedValue(); 
                    bg.setColor(info.color); 
                } 
            }); 
        } else { 
            // custom image is set by the theme, let's just apply the alpha if we can. 
            v.getBackground().setAlpha(BackgroundAlphaColorDrawable.floatAlphaToInt(alpha)); 
            return null; 
        } 
        anim.addListener(new AnimatorListener() { 
            @Override 
            public void onAnimationStart(Animator animation) {
            } 
            @Override 
            public void onAnimationRepeat(Animator animation) {