Verification Code Countdown in Android

Source: Internet
Author: User
Tags getcolor

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.