Obtain the verification code using Android

Source: Internet
Author: User

Obtain the verification code using Android

The simple function is to define a CountDownTimer to directly view the code.

First, put a button code in XML as follows:

 

 
  
 
The following is the main code:

 

 

Package com. example. countdowntimer; import android. OS. bundle; import android. OS. countDownTimer; import android. app. activity; import android. graphics. color; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. button; public class MainActivity extends Activity {private TimeCount time; private Button btnGetcode; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); time = new TimeCount (60000,100 0); btnGetcode = (Button) findViewById (R. id. btn_getcode); btnGetcode. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {time. start () ;}});} class TimeCount extends CountDownTimer {public TimeCount (long millisInFuture, long countDownInterval) {super (millisInFuture, countDownInterval);} @ Overridepublic void onTick (long timer) {btnGetcode. setBackgroundColor (Color. parseColor (# B6B6D8); btnGetcode. setClickable (false); btnGetcode. setText (millisUntilFinished/1000 + seconds later);} @ Overridepublic void onFinish () {btnGetcode. setText (re-obtain the Verification Code); btnGetcode. setClickable (true); btnGetcode. setBackgroundColor (Color. parseColor (# 4EB84A ));}}}
 

 


 

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.