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

首頁 > 系統 > Android > 正文

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

2019-12-12 00:41:58
字體:
來源:轉載
供稿:網友

本文為大家分享了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(); } }); }}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江达县| 景德镇市| 黄梅县| 晴隆县| 巴塘县| 五莲县| 沛县| 平潭县| 平凉市| 信丰县| 菏泽市| 嘉善县| 百色市| 南川市| 东安县| 武胜县| 上蔡县| 巴彦县| 汨罗市| 颍上县| 沾化县| 行唐县| 扎赉特旗| 石林| 泸定县| 宣城市| 夹江县| 新丰县| 清新县| 中西区| 阳东县| 永德县| 鲁甸县| 平陆县| 绥滨县| 达日县| 枞阳县| 伊宁市| 德庆县| 泸州市| 子洲县|