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

首頁 > 系統 > Android > 正文

Android使用CountDownTimer模擬短信驗證倒計時

2019-10-21 21:46:13
字體:
來源:轉載
供稿:網友

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

Android,CountDownTimer,短信驗證,倒計時

內容:介紹倒計時CountDownTimer的基本使用方法。模擬短信驗證

步驟:

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

2、代碼中new出CountDownTimer子類,傳好參數,調用start()執行

代碼如下:

<?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="獲取短信驗證碼"  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("獲取短信驗證碼"); }}

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:要計數的總時長  * countDownInterval:每隔多少秒響應  */ TimerCount timerCount = new TimerCount(5000, 1000, textView); timerCount.start(); } }); }}

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


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 晋中市| 波密县| 天门市| 白银市| 灵璧县| 汝阳县| 隆昌县| 青州市| 寿光市| 高陵县| 万盛区| 兰考县| 卢湾区| 正阳县| 郎溪县| 开江县| 泸州市| 靖安县| 通城县| 新源县| 星子县| 鹿邑县| 南阳市| 柏乡县| 德州市| 呼伦贝尔市| 周口市| 邹平县| 丽水市| 阿拉尔市| 沙田区| 治县。| 微山县| 卢氏县| 雷山县| 双辽市| 澄迈县| 上栗县| 敦煌市| 五大连池市| 新郑市|