欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android使用CountDownTimer模擬短信驗(yàn)證倒計時

 更新時間:2018年07月20日 09:20:31   作者:Mr_Leixiansheng  
這篇文章主要為大家詳細(xì)介紹了Android使用CountDownTimer模擬短信驗(yàn)證倒計時,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了CountDownTimer模擬短信驗(yàn)證倒計時的具體代碼,供大家參考,具體內(nèi)容如下

內(nèi)容:介紹倒計時CountDownTimer的基本使用方法。模擬短信驗(yàn)證

步驟:

1、繼承CountDownTimer,重寫onTick()、onFinish()

2、代碼中new出CountDownTimer子類,傳好參數(shù),調(diào)用start()執(zhí)行

代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.leixiansheng.countdowntimer.MainActivity">
 
 <TextView
  android:id="@+id/tv_getMsg"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerInParent="true"
  android:text="獲取短信驗(yàn)證碼"
  android:background="@color/colorPrimaryDark"
  android:textSize="16sp"
  android:textColor="#ffffffff" />
</RelativeLayout>

TimerCount

package com.example.leixiansheng.countdowntimer;
 
import android.os.CountDownTimer;
import android.widget.TextView;
 
/**
 * Created by Leixiansheng on 2018/7/18.
 */
 
public class TimerCount extends CountDownTimer {
 
 private TextView mTextView;
 
 
 public TimerCount(long millisInFuture, long countDownInterval, TextView textView) {
 super(millisInFuture, countDownInterval);
 mTextView = textView;
 }
 
 @Override
 public void onTick(long millisUntilFinished) {
 mTextView.setClickable(false);
 mTextView.setText("重新獲取" + millisUntilFinished / 1000 + "秒");
 }
 
 @Override
 public void onFinish() {
 mTextView.setClickable(true);
 mTextView.setText("獲取短信驗(yàn)證碼");
 }
}

Main

package com.example.leixiansheng.countdowntimer;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
 
public class MainActivity extends AppCompatActivity {
 
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 final TextView textView = (TextView) findViewById(R.id.tv_getMsg);
 textView.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 /**
  * millisInFuture:要計數(shù)的總時長
  * countDownInterval:每隔多少秒響應(yīng)
  */
 TimerCount timerCount = new TimerCount(5000, 1000, textView);
 timerCount.start();
 }
 });
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。 

相關(guān)文章

  • Android中TextView顯示圓圈背景或設(shè)置圓角的方法

    Android中TextView顯示圓圈背景或設(shè)置圓角的方法

    TextView顯示文本給用戶,并允許他們選擇編輯。TextView是一個完整的文本編輯器,但是其基本類配置為不允許編輯。下面這篇文章主要給大家介紹了關(guān)于Android中TextView顯示圓圈背景或設(shè)置圓角的方法,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-05-05
  • Android Handler leak分析及解決辦法詳解

    Android Handler leak分析及解決辦法詳解

    這篇文章主要介紹了Android Handler leak分析及解決辦法詳解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android編程實(shí)現(xiàn)全局獲取Context及使用Intent傳遞對象的方法詳解

    Android編程實(shí)現(xiàn)全局獲取Context及使用Intent傳遞對象的方法詳解

    這篇文章主要介紹了Android編程實(shí)現(xiàn)全局獲取Context及使用Intent傳遞對象的方法,結(jié)合實(shí)例形式分析了Android全局Context的獲取及Intent傳遞對象的具體操作方法,需要的朋友可以參考下
    2017-08-08
  • Android Jetpack組件中LiveData的優(yōu)劣

    Android Jetpack組件中LiveData的優(yōu)劣

    LiveData是Jetpack組件的一部分,更多的時候是搭配ViewModel來使用,相對于Observable,LiveData的最大優(yōu)勢是其具有生命感知的,換句話說,LiveData可以保證只有在組件(?Activity、Fragment、Service)處于活動生命周期狀態(tài)的時候才會更新數(shù)據(jù)
    2023-04-04
  • kotlin Context使用詳解

    kotlin Context使用詳解

    這篇文章主要介紹了kotlin Context使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • android 中ProgressDialog實(shí)現(xiàn)全屏效果的示例

    android 中ProgressDialog實(shí)現(xiàn)全屏效果的示例

    本篇文章主要介紹了android 中ProgressDialog實(shí)現(xiàn)全屏效果的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • Android開發(fā)利器之pidcat安裝方式

    Android開發(fā)利器之pidcat安裝方式

    pidcat 是Android屆JakeWharton大神開發(fā)的一款命令行工具,堪稱Android開發(fā)利器,它能方便Android程序猿捕獲日志,過濾日志,定位程序問題,超級好用。這篇文章給大家介紹了Android開發(fā)利器之pidcat,需要的朋友可以參考下
    2019-05-05
  • Android自定義控件實(shí)現(xiàn)九宮格解鎖

    Android自定義控件實(shí)現(xiàn)九宮格解鎖

    這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)九宮格解鎖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • Android編程使用Intent傳遞對象的方法分析

    Android編程使用Intent傳遞對象的方法分析

    這篇文章主要介紹了Android編程使用Intent傳遞對象的方法,結(jié)合實(shí)例形式詳細(xì)分析了Android使用Intent實(shí)現(xiàn)傳遞對象的相關(guān)技巧與注意事項(xiàng),需要的朋友可以參考下
    2016-01-01
  • Android框架Volley使用之Json請求實(shí)現(xiàn)

    Android框架Volley使用之Json請求實(shí)現(xiàn)

    這篇文章主要介紹了Android框架Volley使用之Json請求實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-05-05

最新評論