Android 获取验证码按钮倒计时实现工具类
  ttOzQgS7km1w 2023年12月11日 48 0


使用介绍

TimerCount timer = new TimerCount(60000, 1000, code);                   
       timer.start();

工具类代码

import android.os.CountDownTimer;
 import android.widget.Button;import com.xinli.wenet.base.MyApplication;
 import com.xinli.wenet.R; /**
  * The type Timer count.
  */
 public class TimerCount extends CountDownTimer {
     private Button bnt;    /**
      * Instantiates a new Timer count.
      *
      * @param millisInFuture    the millis in future
      * @param countDownInterval the count down interval
      * @param bnt               the bnt
      */
     public TimerCount(long millisInFuture, long countDownInterval, Button bnt) {
         super(millisInFuture, countDownInterval);
         this.bnt = bnt;
     }    /**
      * Instantiates a new Timer count.
      *
      * @param millisInFuture    the millis in future
      * @param countDownInterval the count down interval
      */
     public TimerCount(long millisInFuture, long countDownInterval) {
         super(millisInFuture, countDownInterval);
         // TODO Auto-generated constructor stub
     }    @Override
     public void onFinish() {        bnt.setClickable(true);
         bnt.setTextColor(MyApplication.getAppContext().getResources().getColor(R.color.colorBlue));
         bnt.setText("获取动态码");    }
    @Override
     public void onTick(long arg0) {
         // TODO Auto-generated method stub
         bnt.setClickable(false);
         bnt.setText(arg0 / 1000 + "秒后重新获取");
         bnt.setTextColor(MyApplication.getAppContext().getResources().getColor(R.color.colorLine));
     }
 }
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月11日 0

暂无评论

推荐阅读
ttOzQgS7km1w