继承CountDownTimer ,new 一个对象,调用start即可。
自定义 类
private class Count extends CountDownTimer {
public Count(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
send.setEnabled(false);
send.setText(millisUntilFinished / 1000 + "秒");
}
@Override
public void onFinish() {
send.setEnabled(true);
send.setText("重新发送");
}
public void remove() {
cancel();
send.setEnabled(true);
send.setText("发送验证码");
}
}
if (count == null) {
count = new Count(60000, 1000);
}
count.start();