zoukankan      html  css  js  c++  java
  • Android开发(五)——计时器

    发送验证码后倒计时,Android自带计时器CountDownTimer,重写自己的计时器以实现跟新View的效果。

    package com.lgaoxiao.widget;
    
    import android.os.CountDownTimer;
    import android.widget.TextView;
    
    /**
     * TextView的计时器
     * @author TimZhang
     *
     */
    public class MyCountTimer extends CountDownTimer {
        private TextView btn;
        private int normalColor,timingColor;
        private String normalText;
        
        /**
         * @param millisInFuture
         * @param countDownInterval
         * @param v TextView
         * @param nColor Normal Color
         * @param tColor Timing Color
         */
        public MyCountTimer(long millisInFuture, long countDownInterval,TextView v,int nColor,int tColor) {
            super(millisInFuture, countDownInterval);
            this.btn = v;
            this.normalColor = nColor;
            this.timingColor = tColor;
            this.normalText = v.getText().toString();
        }
    
        @Override
        public void onTick(long millisUntilFinished) {
            btn.setBackgroundColor(timingColor);
            btn.setEnabled(false);
            btn.setText(millisUntilFinished / 1000 + "s");
            
        }
    
        @Override
        public void onFinish() {
            btn.setEnabled(true);
            btn.setBackgroundColor(normalColor);
            btn.setText(normalText);
        }
    
    }

    参考:http://www.open-open.com/code/view/1426335036826

  • 相关阅读:
    Array 对象-sort()
    vue安装
    前端面试题
    JavaScript对象原型
    CSS如何水平垂直居中?
    块格式化上下文(Block Formatting Context,BFC)
    盒子模型
    前端基础
    Markdown语法
    浏览器 滚动条 占据 y轴宽度的解决方案
  • 原文地址:https://www.cnblogs.com/ccdc/p/4431311.html
Copyright © 2011-2022 走看看