国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現點擊獲取驗證碼60秒后重新獲取功能

2019-12-12 00:49:05
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android實現點擊獲取驗證碼60秒后重新獲取的具體代碼,供大家參考,具體內容如下

上代碼

/** * Created by Xia_焱 on 2017/5/7. */public class CountDownTimerUtils extends CountDownTimer {  private TextView mTextView;  /**   * @param millisInFuture  The number of millis in the future from the call   *             to {@link #start()} until the countdown is done and {@link #onFinish()}   *             is called.   * @param countDownInterval The interval along the way to receive   *             {@link #onTick(long)} callbacks.   */  public CountDownTimerUtils(TextView textView, long millisInFuture, long countDownInterval) {    super(millisInFuture, countDownInterval);    this.mTextView = textView;  }  @Override  public void onTick(long millisUntilFinished) {    mTextView.setClickable(false); //設置不可點擊    mTextView.setText(millisUntilFinished / 1000 + "秒后可重新發送"); //設置倒計時時間    mTextView.setBackgroundResource(R.drawable.bg_identify_code_press); //設置按鈕為灰    SpannableString spannableString = new SpannableString(mTextView.getText().toString());    ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);    spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);    mTextView.setText(spannableString);  }  @Override  public void onFinish() {    mTextView.setText("重新獲取驗證碼");    mTextView.setClickable(true);//重新獲得點擊    mTextView.setBackgroundResource(R.drawable.bg_identify_code_normal);  }}

TextView背景色

bg_identify_code_press

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">  <solid android:color="#C0C0C0" /> <!--填充色 透明-->  <corners android:radius="7dp" /> <!-- 圓角 --></shape>

bg_identify_code_normal

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">  <solid android:color="#2BAF2B" /> <!--填充色 透明-->  <corners android:radius="7dp" /> <!-- 圓角 --></shape>

布局代碼

 <TextView    android:id="@+id/tv_yzm"    android:layout_width="match_parent"    android:layout_marginTop="50dp"    android:layout_height="45dp"    android:background="@drawable/bg_identify_code_normal"    android:gravity="center"    android:text="點擊獲取驗證碼"    android:textColor="#FFF"    android:textSize="15dp" />

項目代碼

 private void initView() {    tv_yzm = (TextView) findViewById(R.id.tv_yzm);    tv_yzm.setOnClickListener(new View.OnClickListener() {      @Override      public void onClick(View v) {        CountDownTimerUtils mCountDownTimerUtils = new CountDownTimerUtils(tv_yzm, 60000, 1000);        mCountDownTimerUtils.start();      }    });  }

效果圖

這里寫圖片描述

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 溆浦县| 利川市| 额敏县| 柘荣县| 开平市| 昭平县| 越西县| 左权县| 明光市| 茂名市| 伊川县| 会同县| 珲春市| 遵义市| 蓬安县| 永善县| 罗江县| 江西省| 青海省| 英山县| 平原县| 乡宁县| 社旗县| 永登县| 湘乡市| 德昌县| 临泽县| 福建省| 河曲县| 兖州市| 西平县| 邻水| 比如县| 股票| 易门县| 托克逊县| 东乌珠穆沁旗| 朝阳区| 政和县| 广饶县| 海伦市|