CountDownTimer timer = new CountDownTimer(10000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
tv_yzm.setEnabled(false);
tv_yzm.setText("已發(fā)送(" + millisUntilFinished / 1000 + ")");
}
@Override
public void onFinish() {
tv_yzm.setEnabled(true);
tv_yzm.setText("獲取驗(yàn)證碼");
}
}.start();
@Override
protected void onDestroy() {
super.onDestroy();
if (timer!=null){
timer.cancel();
}
}
詳細(xì)說(shuō)明參考:https://blog.csdn.net/weixin_42564441/article/details/80967482