Android开发(五)——计时器
生活随笔
收集整理的這篇文章主要介紹了
Android开发(五)——计时器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
發送驗證碼后倒計時,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();}@Overridepublic void onTick(long millisUntilFinished) {btn.setBackgroundColor(timingColor);btn.setEnabled(false);btn.setText(millisUntilFinished / 1000 + "s");}@Overridepublic void onFinish() {btn.setEnabled(true);btn.setBackgroundColor(normalColor);btn.setText(normalText);}}?
參考:http://www.open-open.com/code/view/1426335036826
總結
以上是生活随笔為你收集整理的Android开发(五)——计时器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于xmpp协议发送消息,登录认证SSL
- 下一篇: 浅谈:Android应用清理内存