Countdown instance code of Android custom view
Countdown example code of Android custom view
Requirements:
When registering, most apps have a button to obtain the verification code. Click it to access the interface, and the end user will receive the SMS verification code. In order not to write this interface for obtaining verification code many times, it is customized into a view for ease of use.
After analysis, this is a textview. When clicking, it changes color and cannot be clicked again. At the same time, the countdown inside starts to display. Then you have the following code
code:
Test code:
Summary:
1, when you use it, set the click event for the control, then call the start () method, and the rest is your own code, usually the network interface.
2. The control background for obtaining the verification code can be set as the selector and Android: state_ Enabled property. The selector code of the above example is as follows:
3. When exiting the activity, remember to call the cancel method of the control to destroy it, otherwise it will cause memory leakage.
Thank you for reading, hope to help you, thank you for your support to this site!