Android實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼60秒后重新獲取功能
本文實(shí)例為大家分享了Android實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼60秒后重新獲取的具體代碼,供大家參考,具體內(nèi)容如下
上代碼
/**
* 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); //設(shè)置不可點(diǎn)擊
mTextView.setText(millisUntilFinished / 1000 + "秒后可重新發(fā)送"); //設(shè)置倒計(jì)時(shí)時(shí)間
mTextView.setBackgroundResource(R.drawable.bg_identify_code_press); //設(shè)置按鈕為灰
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("重新獲取驗(yàn)證碼");
mTextView.setClickable(true);//重新獲得點(diǎn)擊
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="點(diǎn)擊獲取驗(yàn)證碼"
android:textColor="#FFF"
android:textSize="15dp" />
項(xiàng)目代碼
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();
}
});
}
效果圖

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)滑塊拼圖驗(yàn)證碼功能
- Android本地驗(yàn)證碼的生成代碼
- Android自定義控件實(shí)現(xiàn)通用驗(yàn)證碼輸入框
- Android自定義View驗(yàn)證碼輸入框
- Android 使用fast-verification實(shí)現(xiàn)驗(yàn)證碼填寫功能的實(shí)例代碼
- Android實(shí)現(xiàn)自定義驗(yàn)證碼輸入框效果(實(shí)例代碼)
- Android自定義控件實(shí)現(xiàn)短信驗(yàn)證碼自動(dòng)填充
- Android 自定義驗(yàn)證碼輸入框的實(shí)例代碼(支持粘貼連續(xù)性)
- Android短信驗(yàn)證碼自動(dòng)填寫實(shí)現(xiàn)代碼
- Android 簡單的實(shí)現(xiàn)滑塊拼圖驗(yàn)證碼功能
相關(guān)文章
Android 中 Activity顯示隱式跳轉(zhuǎn)
這篇文章主要介紹了Android 中 Activity顯示隱式跳轉(zhuǎn)的實(shí)現(xiàn)方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02
Android開發(fā)實(shí)現(xiàn)文件存儲(chǔ)功能
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)實(shí)現(xiàn)文件存儲(chǔ)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07
Android 如何獲取設(shè)備唯一標(biāo)識(shí)
這篇文章主要介紹了Android 如何獲取設(shè)備唯一標(biāo)識(shí),幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03
Android 中使用RecyclerView實(shí)現(xiàn)底部翻頁
這篇文章主要介紹了Android 中使用RecyclerView實(shí)現(xiàn)底部翻頁功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-11-11
Android UI控件之ListView實(shí)現(xiàn)圓角效果
這篇文章主要為大家詳細(xì)介紹了Android UI控件之ListView實(shí)現(xiàn)圓角效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android 日期和時(shí)間的使用實(shí)例詳解
這篇文章主要介紹了Android 日期和時(shí)間的使用實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2016-12-12
Android ViewPager撤消左右滑動(dòng)切換功能實(shí)現(xiàn)代碼
這篇文章主要介紹了Android ViewPager撤消左右滑動(dòng)切換功能實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-04-04
Android RecyclerView選擇多個(gè)item的實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Android RecyclerView選擇多個(gè)item的實(shí)現(xiàn)代碼,仿網(wǎng)易新聞客戶端頻道選擇效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02

