import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.Button;
// 验证码发送间隔60秒
public class TimeCountextends CountDownTimer {
int color = Color.parseColor("#ffffff");
private Buttonbutton;
/**
* @param millisInFuture 总时间
*
*
* @param countDownInterval 间隔多少秒
*@param button 传入button控件
*/
public TimeCount(long millisInFuture,long countDownInterval, Button button) {
super(millisInFuture, countDownInterval);
this.button=button;
}
@SuppressLint("SetTextI18n")
@Override
public void onTick(long millisUntilFinished) {
button.setTextColor(color);
button.setClickable(false);
button.setText("("+millisUntilFinished /1000 +") 秒后重发");
}
@Override
public void onFinish() {
button.setText("重新获取");
button.setClickable(true);
button.setTextColor(color);
}
}
// 使用
private TimeCounttimeCount;
timeCount =new TimeCount(60000,1000,button);
// button点击事件里面
timeCount.start();
// 效果