Android development to get SMS verification code after the button background changes and the countdown _android

Source: Internet
Author: User
Tags time interval

Now more and more apps are registering or doing the corresponding operation, request to obtain the SMS authentication code, click to obtain the SMS Verification Code button, is the countdown, such as Countdown 120S, in the countdown period, the button background changes and the countdown, when the countdown is over, if you do not get the verification code, You can click again.

The code looks like this:

Vercodetimer mvercodetimer= (Button) Findviewbyid (R.id.login_get_ver_code);
    Private class Vercodetimer extends Countdowntimer {private int seconds;
    private int interval;
    Millisinfuture for you to set the total length of the countdown, such as 60 seconds set to 60000//countdowninterval for you to set the time interval, such as the general 1 seconds, as needed to customize.
      Public Vercodetimer (Long millisinfuture, long Countdowninterval) {super (millisinfuture, countdowninterval);
      seconds = (int) (millisinfuture/1000);
    interval= (int) (countdowninterval/1000); The Operation @Override public void Ontick (long millisuntilfinished) {Getvercodebutton.settext)//Every time interval you specify (SE
    Conds-interval) + "seconds to regain");
      The operation at the end of the countdown ↓↓ @Override public void OnFinish () {getvercodebutton.settextsize (10);
      Getvercodebutton.settext ("re-obtaining verification Code");
      Getvercodebutton.setclickable (TRUE);
    Getvercodebutton.setbackgroundresource (R.DRAWABLE.LOGIN_GET_VER_CODE_BEFORE_BG); @Override public void onbackpressed () {if mvercodEtimer!= null) mvercodetimer.cancel ();
  Super.onbackpressed ();  }

When in use:

Getvercodebutton.settextsize (one);
 Getvercodebutton.setclickable (false);
 Getvercodebutton.setbackgroundresource (R.DRAWABLE.LOGIN_GET_VER_CODE_AGO_BG);
 Mvercodetimer = new Vercodetimer (60000, 1000);
 

Login_edit_normal_bg.xml:

<?xml version= "1.0" encoding= "UTF-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android "
  android:shape=" Rectangle "
  android:uselevel=" false ">
  <!--background fill color value-->
  < Solid android:color= "#6c948b"/>
  <!--The larger the radius value, the more rounded-->
  <corners android:radius= "10dip"/ >
  <!--the size of the inner padding around the fillet image will squeeze the interior layout view-->
  <padding
    android:bottom= "10dip"
    Android : left= "10dip"
    android:right= "10dip"
    android:top= "10dip"/>

Login_edit_passed_bg.xml:

<?xml version= "1.0" encoding= "UTF-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android "
  android:shape=" Rectangle "
  android:uselevel=" false ">
  <!--background fill color value-->
  <solid Android:color= "#509989"/>
  <!--The larger the radius value, the more rounded-->
  <corners android:radius= "10dip"/>
  <!--the size of the inner padding around the rounded image will squeeze the interior layout view-->
  <padding
    android:bottom= "10dip"
    android:left= " 10dip "
    android:right=" 10dip "
    android:top=" 10dip "/>
</shape>

The above is a small series to introduce the Android development to get the SMS verification code after the button background changes and the countdown to all the code, I hope this code can help everyone. At the same time, thank you for your continued support for the cloud-dwelling community website.

Related Article

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.