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

Android實(shí)現(xiàn)驗(yàn)證碼登錄

 更新時(shí)間:2021年03月16日 07:08:02   作者:mo_seele  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)驗(yàn)證碼登錄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)驗(yàn)證碼登錄的具體代碼,供大家參考,具體內(nèi)容如下

結(jié)果展示

1.導(dǎo)包

1.1在項(xiàng)目的gradle中導(dǎo)入

maven { url "https://www.jitpack.io" }

1.2在model的gradle的dependencies導(dǎo)入

//XUI項(xiàng)目
implementation 'com.github.xuexiangjys:XUI:1.1.6'

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'

1.3點(diǎn)擊右上角的sync now

2.新建xml文件

phone_code.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 xmlns:app="http://schemas.android.com/apk/res-auto">


 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginLeft="30dp"
 android:layout_marginTop="50dp"
 android:textSize="25dp"
 android:textStyle="bold"
 android:text="請輸入驗(yàn)證碼"
 />
 <TextView
 android:id="@+id/phone_number_str"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textSize="18dp"
 android:textColor="#000000"
 android:layout_marginLeft="30dp"
 android:layout_marginTop="5dp"
 />

 <com.xuexiang.xui.widget.edittext.verify.VerifyCodeEditText
 android:id="@+id/phone_code_input"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginLeft="10dp"
 android:layout_marginTop="26dp"
 android:layout_marginRight="10dp"
 app:vcet_is_pwd="false"
 app:vcet_number="6"
 app:vcet_pwd_radius="10dp"
 app:vcet_text_color="#000000"
 app:vcet_width="50dp" />

 <TextView
 android:id="@+id/re_get_code"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="20dp"
 android:layout_marginLeft="30dp"
 android:textColor="#60000000"
 android:textSize="20dp"
 />

 <TextView
 android:id="@+id/get_code"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="20dp"
 android:layout_marginLeft="30dp"
 android:textColor="#60000000"
 android:textSize="15dp"
 />

</LinearLayout>

3.修改Activity

MainActivity.java

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;


import java.lang.reflect.Field;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 TextView phoneNumberStr;
 TextView codeCountDown;
 TextView reGetCode;
 private int recLen = 10;

 Timer timer = new Timer();
 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.phone_code);
 init();//初始化組件
 String phone = new String("15968373790");

 if (phone.length() < 11)
  phoneNumberStr.setText("驗(yàn)證碼已發(fā)送至"+phone);
 else
  phoneNumberStr.setText("驗(yàn)證碼已發(fā)送至"+phone.substring(0,3)+"****"+phone.substring(7));
 timer.schedule(task, 1000, 1000); // 啟動一個(gè)1000毫秒(1秒)的定時(shí)任務(wù)

 }

 TimerTask task = new TimerTask() {
 @Override
 public void run() {

  runOnUiThread(new Runnable() {
  @Override
  public void run() {
   codeCountDown.setVisibility(View.VISIBLE);
   recLen--;
   codeCountDown.setText(recLen+"秒后重新獲取驗(yàn)證碼");//動態(tài)調(diào)整秒數(shù)下降
   if(recLen <= 0){
   timer.cancel();
   codeCountDown.setVisibility(View.GONE);
   reGetCode.setText("重新獲得驗(yàn)證碼");//倒計(jì)時(shí)結(jié)束,修改為重新獲得驗(yàn)證碼

   reGetCode.setVisibility(View.VISIBLE);//修改控件的可見性
   reGetCode.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    reGetCode.setVisibility(View.GONE);
    recLen = 10;
    codeCountDown.setVisibility(View.VISIBLE);
    codeCountDown.setText(recLen+"秒后重新獲取驗(yàn)證碼");
    timer = new Timer();
    //task一般情況下使用過一次后無法再使用,但可以借助反射使得task重新工作,修改state屬性即可,state為1時(shí)表示已經(jīng)使用過無法再次使用,為0表示可以使用
    Field field;
    try {
     field = TimerTask.class.getDeclaredField("state");
     field.setAccessible(true);
     field.set(task, 0);
    } catch (NoSuchFieldException e) {
     e.printStackTrace();
    } catch (Exception e) {
     e.printStackTrace();
    }
    timer.schedule(task, 1000, 1000);
    }
   });
   }
  }
  });
 }
 };


 private void init() {

 phoneNumberStr = findViewById(R.id.phone_number_str);
 codeCountDown = findViewById(R.id.re_get_code);
 reGetCode = findViewById(R.id.re_get_code);
 reGetCode.setOnClickListener(this);
 reGetCode.setVisibility(View.GONE);
 }


 @Override
 public void onClick(View v) {
 Intent intent;//設(shè)置單擊事件使得倒計(jì)時(shí)可以繼續(xù)
 switch (v.getId()){
  case R.id.get_code:
  reGetCode.setVisibility(View.GONE);
  timer.schedule(task, 1000, 1000); // timeTask
  break;
 }
 }
}

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

相關(guān)文章

  • Android Jni的簡單使用詳解

    Android Jni的簡單使用詳解

    這篇文章主要介紹了Android Jni的簡單使用詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-02-02
  • Android VNDK使用及原理深入探究

    Android VNDK使用及原理深入探究

    這篇文章主要為大家介紹了Android VNDK使用及原理深入探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • Android對話框自定義標(biāo)題 對話框標(biāo)題美化操作

    Android對話框自定義標(biāo)題 對話框標(biāo)題美化操作

    這篇文章主要為大家詳細(xì)介紹了Android對話框自定義標(biāo)題的相關(guān)資料,如何對對話框標(biāo)題進(jìn)行美化操作,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android開發(fā)的IDE、ADT、SDK、JDK、NDK等名詞解釋

    Android開發(fā)的IDE、ADT、SDK、JDK、NDK等名詞解釋

    這篇文章主要介紹了Android開發(fā)的IDE、ADT、SDK、JDK、NDK等名詞解釋,對這些概念搞不清楚是一件痛苦的事,本文就簡潔講解了這些名詞的含義,一起掃盲吧,需要的朋友可以參考下
    2015-06-06
  • 深入分析Android加載so文件源碼

    深入分析Android加載so文件源碼

    這篇文章主要介紹了深入分析Android加載so文件源碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • Android自定義View實(shí)現(xiàn)折線圖效果

    Android自定義View實(shí)現(xiàn)折線圖效果

    這篇文章介紹的是一個(gè)折線圖控件,用來顯示一系列的狀態(tài),并可以進(jìn)行滑動。有需要的可以參考借鑒。
    2016-08-08
  • Android實(shí)現(xiàn)刮刮樂示例分析

    Android實(shí)現(xiàn)刮刮樂示例分析

    本文實(shí)現(xiàn)了Android刮刮樂示例分析,刮獎在生活中常常見到,網(wǎng)上現(xiàn)在也有各種各樣的抽獎活動,下面我們就要實(shí)現(xiàn)一個(gè)刮刮樂程序。
    2016-10-10
  • Android操作SQLite基本用法

    Android操作SQLite基本用法

    這篇文章主要介紹了Android操作SQLite基本用法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2021-12-12
  • Android?Canva實(shí)現(xiàn)漸變進(jìn)度條

    Android?Canva實(shí)現(xiàn)漸變進(jìn)度條

    這篇文章主要為大家介紹了Android?Canva實(shí)現(xiàn)漸變進(jìn)度條示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • 詳解Android Selinux 權(quán)限及問題

    詳解Android Selinux 權(quán)限及問題

    本篇文章主要介紹了詳解Android Selinux 權(quán)限及問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11

最新評論