1. To achieve the effect of a verification code countdown
2. Implement
Get verification code in the figure that block is a button
Key section, declaring a timecount, inheriting from Countdowntimer
/* Verification Code Countdown */
Private class Timecount extends countdowntimer{
/**
* Total length of time @param millisinfuture (MS)
* @param countdowninterval time interval (milliseconds), and the Ontick method is called every time interval elapses
*/
Public Timecount (Long millisinfuture, long Countdowninterval) {
Super (Millisinfuture, countdowninterval);
}
@Override
public void OnTick (long millisuntilfinished) {//Countdown status
Getverificationcodebtn.setclickable (FALSE); Setting button is not clickable at this time
Getverificationcodebtn.setbackground (Getresources (). getdrawable (R.DRAWABLE.GET_VERIFICATION_CODE_WAITTING_BG)) ;//Modify the background of the button
Getverificationcodebtn.settextcolor (Getresources (). GetColor (R.color.black));//Modify the button's TextColor
Getverificationcodebtn.settext (millisuntilfinished/1000 + "s can Resend");//Display the countdown text of the button
}
@Override
public void OnFinish () {//Countdown end Status
Getverificationcodebtn.setbackground (Getresources (). getdrawable (R.DRAWABLE.LOGIN_BTN_BG));
Getverificationcodebtn.settextcolor (Getresources (). GetColor (R.color.white));
Getverificationcodebtn.setclickable (TRUE); Reset button to clickable
Getverificationcodebtn.settext ("Re-acquisition"); Modify the text of a button
}
}
Finally, in the code, the Declaration is timecount and instantiated, called in the button's Click event. The start () method starts the timer.
Timecount timecount = new Timecount (60000,1000);
Timecount.start ();
This concludes.
Verification Code Countdown in Android