android--------验证码倒计时
2024-09-28 09:50:02
在我们注册或者修改信息的时候,常会用到60s倒计时这个功能,写了这篇文章,大家共享一下:
效果图:
直接上代码:
activity.java
public class MainActivity extends Activity { private TimeCount mTiemTimeCount;
private TextView tv_code; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTiemTimeCount = new TimeCount(60000, 1000);
initView(); } private void initView() {
// TODO Auto-generated method stub
tv_code = (TextView) findViewById(R.id.verify_code);
tv_code.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mTiemTimeCount.start();
}
});
} // 计时重发
private class TimeCount extends CountDownTimer { public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
} @Override
public void onTick(long millisUntilFinished) {
tv_code.setClickable(false);
tv_code.setText(millisUntilFinished / 1000 + "秒后重新发送");
} @Override
public void onFinish() {
tv_code.setText("获取验证码");
tv_code.setClickable(true);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mTiemTimeCount.cancel();
}
}
mTiemTimeCount = new TimeCount(60000, 1000);可以自己更改时间
代码简单可直接使用
源码下载: https://github.com/DickyQie/android-layout-controls
最新文章
- SQL Server-表表达式基础回顾(二十四)
- 史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。
- Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境
- 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: Section 4 Dependent Samples
- python学习之安装模块
- git撤销commit
- Swift - UIView的无损截图
- MySQL 获得当前日期时间(以及时间的转换)
- PHP抓取豆瓣读书爬虫代码
- CKRule BRMS-决策表使用说明
- 基于JSP+SERVLET的新闻发布系统(二)
- 基于Linux根据僵尸网络病毒平台《比尔盖茨》
- 运行ORB-SLAM笔记_编译篇(一)
- ucos信号量集源码分析
- linux-Centos6.5中nginx1.63源码安装
- Python实战之实现简单的登陆系统-作业
- C#中的GET和SET访问器
- redis集群配置与管理
- Collections.unmodifiableMap(Map map)
- Redux和react-redux的学习总结
热门文章
- Linux服务器---apache支持SSL
- QAQ的LIS树 QAQ的LIS树2 题解报告
- leetcode 136 Single Number, 260 Single Number III
- 利用构建缓存机制缩短Docker镜像构建时间
- SPOJ Prime or Not - 快速乘 - 快速幂
- 一种新的技术,C++/CLI
- Mysql相关问题收集
- [BZOJ4244]邮戳拉力赛
- C#入门经典 第六章 委托
- 论文笔记之:UNSUPERVISED REPRESENTATION LEARNING WITH DEEP CONVOLUTIONAL GENERATIVE ADVERSARIAL NETWORKS