animate TextView by ObjectAnimator - Android android.animation

Android examples for android.animation:ObjectAnimator

Description

animate TextView by ObjectAnimator

Demo Code


//package com.java2s;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.util.Property;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;

public class Main {
    static Property<TextView, Integer> property = new Property<TextView, Integer>(
            int.class, "textColor") {
        @Override/*from   www .  j  a  v a2 s.c o  m*/
        public Integer get(TextView object) {
            return object.getCurrentTextColor();
        }

        @Override
        public void set(TextView object, Integer value) {
            object.setTextColor(value);
        }
    };
    static ObjectAnimator animator;

    public static void animate(TextView tv, int... color) {
        animator = ObjectAnimator.ofInt(tv, property, color);
        animator.setEvaluator(new ArgbEvaluator());
        animator.setDuration(300);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.start();
    }
}

Related Tutorials