Android开发(五)——计时器
2024-10-19 08:48:57
发送验证码后倒计时,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
最新文章
- linux定时备份mysql并同步到其它服务器
- CSS中定义CLASS时,中间有空格和没空格的区别是什么?
- KnockoutJS 3.X API 第六章 组件(4) 自定义元素
- 【弱省胡策】Round #7 Rectangle 解题报告
- MongoDB实战指南(五):MongoDB中的聚集分析
- ci 用本身 email 类发 email
- 初学socket,c语言写的简单局域网聊天
- centos 用户切换
- 多路复用I/O epoll()
- atom写文档技巧
- 第一个Spark程序
- 1059: [ZJOI2007]矩阵游戏
- iOS升级HTTPS通过ATS你所要知道的
- lvs为何不能完全替代DNS轮询
- Confluence 6 配置 workbox 通知
- MBP 使用笔记
- 51nod 1295 XOR key | 可持久化Trie树
- c#程序员机试题
- Python实践练习:电话号码和 E-mail 地址提取程序
- out参数
热门文章
- windbg-.foreach循环输入(windbg script)
- windows下如何生成gitlab ssh公钥
- 【Android】如何获取本机号码、IMSI、EMSI
- [MSP430] 对MSP430单片机__delay_cycles精确延时的说明及改正
- Aborted connection 1055898 to db: 'xxx' user: 'yyy' host: 'xxx.xxx.xxx.xxx' (Got timeout reading communication packets)
- Innodb的内存结构
- 【转载】Oracle死锁概念,阻塞产生的原因以及解决方案
- Android长度单位详解(dp、sp、px、in、pt、mm、dip)
- [LintCode] Subarray Sum &; Subarray Sum II
- C++/C课程设计(2)工资管理系统功能说明