At present, more and more apps require you to obtain SMS verification code when registering or performing corresponding operations. After clicking the button to obtain SMS verification code, a countdown appears, such as 120S. During the countdown period, the button background changes and a countdown occurs. When the countdown is over, if you do not obtain the verification code, you can click again.
The code looks like this:
VerCodeTimer mVerCodeTimer=(Button) findViewById(.login_get_ver_code); private class VerCodeTimer extends CountDownTimer { private int seconds; private int interval; //millisInFuture sets the total countdown time for you, for example, 60 seconds is set to 60,000 //countDownInterval sets the time interval for you, for example, it is usually 1 second, and customize it as needed. public VerCodeTimer(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); seconds = (int) (millisInFuture / 1000); interval= (int) (countDownInterval/1000); } //Actions done every time you specify the time interval @Override public void onTick(long millisUntilFinished) { ((seconds-interval) + "Regain in seconds"); } //Operation done at the end of the countdown↓↓ @Override public void onFinish() { (10); ("Reacquire verification code"); (true); (.login_get_ver_code_before_bg); } } @Override public void onBackPressed() { if (mVerCodeTimer != null) (); (); }
When using:
(11); (false); (.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:andro android:shape="rectangle" android:useLevel="false"> <!-- Background fill color value --> <solid android:color="#6c948b" /> <!-- radiusThe greater the value,More round --> <corners android:radius="10dip" /> <!-- The size of the rounded corner image inside fills the surrounding ,This will be used to squeeze the inner arrangementview --> <padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" /> </shape>
login_edit_passed_bg.xml:
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:andro android:shape="rectangle" android:useLevel="false"> <!-- Background fill color value --> <solid android:color="#509989" /> <!-- radiusThe greater the value,More round --> <corners android:radius="10dip" /> <!-- The size of the rounded corner image inside fills the surrounding ,This will be used to squeeze the inner arrangementview --> <padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" /> </shape>
The above is the editor introducing all the codes for Android development that change the background of the button after obtaining the SMS verification code and the countdown appears. I hope this code can help you. Also, thank you for your support for my website.