发送验证码后倒计时,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

最新文章

  1. linux定时备份mysql并同步到其它服务器
  2. CSS中定义CLASS时,中间有空格和没空格的区别是什么?
  3. KnockoutJS 3.X API 第六章 组件(4) 自定义元素
  4. 【弱省胡策】Round #7 Rectangle 解题报告
  5. MongoDB实战指南(五):MongoDB中的聚集分析
  6. ci 用本身 email 类发 email
  7. 初学socket,c语言写的简单局域网聊天
  8. centos 用户切换
  9. 多路复用I/O epoll()
  10. atom写文档技巧
  11. 第一个Spark程序
  12. 1059: [ZJOI2007]矩阵游戏
  13. iOS升级HTTPS通过ATS你所要知道的
  14. lvs为何不能完全替代DNS轮询
  15. Confluence 6 配置 workbox 通知
  16. MBP 使用笔记
  17. 51nod 1295 XOR key | 可持久化Trie树
  18. c#程序员机试题
  19. Python实践练习:电话号码和 E-mail 地址提取程序
  20. out参数

热门文章

  1. windbg-.foreach循环输入(windbg script)
  2. windows下如何生成gitlab ssh公钥
  3. 【Android】如何获取本机号码、IMSI、EMSI
  4. [MSP430] 对MSP430单片机__delay_cycles精确延时的说明及改正
  5. Aborted connection 1055898 to db: 'xxx' user: 'yyy' host: 'xxx.xxx.xxx.xxx' (Got timeout reading communication packets)
  6. Innodb的内存结构
  7. 【转载】Oracle死锁概念,阻塞产生的原因以及解决方案
  8. Android长度单位详解(dp、sp、px、in、pt、mm、dip)
  9. [LintCode] Subarray Sum & Subarray Sum II
  10. C++/C课程设计(2)工资管理系统功能说明