最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之獲取短信驗證碼后按鈕背景變化并且出現(xiàn)倒計時

 更新時間:2016年01月08日 16:38:48   投稿:mrr  
在開發(fā)是經(jīng)常會遇到獲取短信驗證碼,然后獲取驗證碼后需要等待n秒倒計時,這時是不能再次發(fā)送短信請求的,這是需要一個倒計時程序,本文給大家分享了實現(xiàn)此功能的代碼,需要的朋友參考下

目前越來越多的app在注冊或是進(jìn)行對應(yīng)操作時,要求獲取短信驗證碼,在點擊了獲取短信驗證碼的按鈕后,就是出現(xiàn)倒計時,比如倒計時120S,在倒計時期間內(nèi),按鈕背景變化并且出現(xiàn)倒計時,當(dāng)?shù)褂嫊r結(jié)束后,如果你沒有獲取到驗證碼,可以再次點擊。

代碼如下所示:

VerCodeTimer mVerCodeTimer=(Button) findViewById(R.id.login_get_ver_code);
private class VerCodeTimer extends CountDownTimer {
    private int seconds;
    private int interval;
    //millisInFuture為你設(shè)置的此次倒計時的總時長,比如60秒就設(shè)置為60000
    //countDownInterval為你設(shè)置的時間間隔,比如一般為1秒,根據(jù)需要自定義。
    public VerCodeTimer(long millisInFuture, long countDownInterval) {
      super(millisInFuture, countDownInterval);
      seconds = (int) (millisInFuture / 1000);
      interval= (int) (countDownInterval/1000);
    }
    //每過你規(guī)定的時間間隔做的操作
    @Override
    public void onTick(long millisUntilFinished) {
      getVerCodeButton.setText((seconds-interval) + "秒后重新獲取");
    }
    //倒計時結(jié)束時做的操作↓↓
    @Override
    public void onFinish() {
      getVerCodeButton.setTextSize(10);
      getVerCodeButton.setText("重新獲取驗證碼");
      getVerCodeButton.setClickable(true);
      getVerCodeButton.setBackgroundResource(R.drawable.login_get_ver_code_before_bg);
    }
  }
  
 @Override
  public void onBackPressed() {
    if (mVerCodeTimer != null)
      mVerCodeTimer.cancel();
    super.onBackPressed();
  } 

使用的時候:

getVerCodeButton.setTextSize(11);
 getVerCodeButton.setClickable(false);
 getVerCodeButton.setBackgroundResource(R.drawable.login_get_ver_code_ago_bg);
 mVerCodeTimer = new VerCodeTimer(60000, 1000);
 mVerCodeTimer.start(); 

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">
  <!-- 背景填充顏色值 -->
  <solid android:color="#6c948b" />
  <!-- radius值越大,越趨于圓形 -->
  <corners android:radius="10dip" />
  <!-- 圓角圖像內(nèi)部填充四周的大小 ,將會以此擠壓內(nèi)部布置的view -->
  <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:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle"
  android:useLevel="false">
  <!-- 背景填充顏色值 -->
  <solid android:color="#509989" />
  <!-- radius值越大,越趨于圓形 -->
  <corners android:radius="10dip" />
  <!-- 圓角圖像內(nèi)部填充四周的大小 ,將會以此擠壓內(nèi)部布置的view -->
  <padding
    android:bottom="10dip"
    android:left="10dip"
    android:right="10dip"
    android:top="10dip" />
</shape>

以上所述是小編給大家介紹了Android開發(fā)之獲取短信驗證碼后按鈕背景變化并且出現(xiàn)倒計時 的全部代碼,希望本段代碼能夠幫助大家。同時感謝大家一直以來對腳本之家網(wǎng)站的支持。

相關(guān)文章

  • Android基礎(chǔ)之startActivityForResult()的用法詳解

    Android基礎(chǔ)之startActivityForResult()的用法詳解

    這篇文章主要給大家介紹了Android中startActivityForResult()的用法,文中給出了詳細(xì)的介紹與示例代碼,相信對大家的理解和學(xué)習(xí)具有一定參考借鑒價值,有需要的朋友們下面來一起看看吧。
    2017-01-01
  • Android Activity啟動模式之standard實例詳解

    Android Activity啟動模式之standard實例詳解

    這篇文章主要介紹了Android Activity啟動模式之standard,結(jié)合實例形式較為詳細(xì)的分析了Android中活動(Activity)四種啟動模式中的standard相關(guān)注意事項與實現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • 最新評論

    陵川县| 茂名市| 漳平市| 荆州市| 康乐县| 德清县| 龙岩市| 多伦县| 辽宁省| 琼结县| 冀州市| 池州市| 信宜市| 闵行区| 磐安县| 米泉市| 顺昌县| 重庆市| 枣阳市| 崇阳县| 高陵县| 禹城市| 宿州市| 横峰县| 文水县| 增城市| 浮山县| 河北省| 乐昌市| 韶关市| 怀化市| 平陆县| 邓州市| 广河县| 淮南市| 中西区| 博野县| 岳阳市| 东山县| 东乡县| 阿瓦提县|