How to make the textview blinking

前端 未结 11 2080
谎友^
谎友^ 2020-12-02 09:14

Guys i have a textview which i need it to be blinking please help me with it.



        
11条回答
  •  误落风尘
    2020-12-02 09:30

    public final class BlinkEffectUtils {
    
        private static BlinkEffectUtils blinkEffect;
    
        public enum PROPERTY_TYPE {
            BACKGROUND_COLOR,
            TEXT_COLOR
        }
    
        private BlinkEffectUtils() {
        }
    
        public static BlinkEffectUtils getInstance(Context context) {
            if (blinkEffect == null) {
                blinkEffect = new BlinkEffectUtils();
            }
    
            return blinkEffect;
        }
    
        public void setBlinkEffect(Object targetView, PROPERTY_TYPE property_type, int duration, int defaultColor, int effectColor) {
            String propertyName = "";
    
            switch (property_type) {
    
                case TEXT_COLOR:
                    propertyName = "textColor";
                    break;
    
                case BACKGROUND_COLOR:
                    propertyName = "backgroundColor";
                    break;
            }
    
            @SuppressLint("ObjectAnimatorBinding")
            ObjectAnimator anim = ObjectAnimator.ofInt(targetView, propertyName,
                    effectColor,
                    defaultColor);
            anim.setDuration(duration);
            anim.setEvaluator(new ArgbEvaluator());
            anim.setRepeatMode(ValueAnimator.REVERSE);
            anim.setRepeatCount(ValueAnimator.INFINITE);
            anim.start();
    
        }
    
    }
    

提交回复
热议问题