星空网 > 软件开发 > 操作系统

注册时获取验证码常用的倒计时工具

//在这个构造方法里需要传入三个参数,一个是Activity,一个是总的时间millisInFuture,
// 一个是每次减少的时间,最后一个是显倒计时的按钮
用法:
TimeLastUtil timeLastUtil = new TimeLastUtil(this, 60000, 1000, btn);
timeLastUtil.start();



工具类:
public class TimeLastUtil extends CountDownTimer {

private Activity mActivity;
private TextView btn;// 按钮

//在这个构造方法里需要传入三个参数,一个是Activity,一个是总的时间millisInFuture,
// 一个是countDownInterval,然后就是你在哪个按钮上做这个是,就把这个按钮传过来就可以了
public TimeLastUtil(Activity mActivity, long millisInFuture,
long countDownInterval, TextView btn) {
super(millisInFuture, countDownInterval);
this.mActivity = mActivity;
this.btn = btn;
}



@SuppressLint("NewApi")
@Override
public void onFinish() {
btn.setText(R.string.register_regetchecknum);
btn.setClickable(true);// // 重新获得点击
btn.setBackgroundColor(Color.parseColor("#00CCCC"));// 还原背景色
}

@Override
public void onTick(long millisUntilFinished) {
btn.setClickable(false);// 设置不能点击
btn.setText(millisUntilFinished / 1000 + "s后可重新发送");// 设置倒计时时间

// 设置按钮为灰色,这时是不能点击的
btn.setBackgroundColor(Color.GRAY);
Spannable span = new SpannableString(btn.getText().toString());// 获取按钮的文字
span.setSpan(new ForegroundColorSpan(Color.RED), 0, 2,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);// 讲倒计时时间显示为红色
btn.setText(span);

}

}
 



原标题:注册时获取验证码常用的倒计时工具

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境电商投融资:https://www.goluckyvip.com/tag/36275.html
跨境电商投资:https://www.goluckyvip.com/tag/36276.html
跨境电商投资分析:https://www.goluckyvip.com/tag/36277.html
跨境电商图片:https://www.goluckyvip.com/tag/36278.html
跨境电商图片翻译工具:https://www.goluckyvip.com/tag/36279.html
跨境电商图片分析:https://www.goluckyvip.com/tag/36280.html
九华山离哪个城市近?:https://www.vstour.cn/a/408248.html
你更喜欢一个人旅行,还是一群人旅行? :https://www.vstour.cn/a/408249.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流