亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Android實現驗證碼登錄

瀏覽:4日期:2022-09-20 15:26:39

本文實例為大家分享了Android實現驗證碼登錄的具體代碼,供大家參考,具體內容如下

結果展示

Android實現驗證碼登錄

1.導包

1.1在項目的gradle中導入

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

Android實現驗證碼登錄

Android實現驗證碼登錄

1.2在model的gradle的dependencies導入

//XUI項目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’

Android實現驗證碼登錄

Android實現驗證碼登錄

1.3點擊右上角的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='請輸入驗證碼' /> <TextView android: 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: 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: 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: 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('驗證碼已發送至'+phone); else phoneNumberStr.setText('驗證碼已發送至'+phone.substring(0,3)+'****'+phone.substring(7)); timer.schedule(task, 1000, 1000); // 啟動一個1000毫秒(1秒)的定時任務 } TimerTask task = new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { codeCountDown.setVisibility(View.VISIBLE); recLen--; codeCountDown.setText(recLen+'秒后重新獲取驗證碼');//動態調整秒數下降 if(recLen <= 0){ timer.cancel(); codeCountDown.setVisibility(View.GONE); reGetCode.setText('重新獲得驗證碼');//倒計時結束,修改為重新獲得驗證碼 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+'秒后重新獲取驗證碼'); timer = new Timer(); //task一般情況下使用過一次后無法再使用,但可以借助反射使得task重新工作,修改state屬性即可,state為1時表示已經使用過無法再次使用,為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;//設置單擊事件使得倒計時可以繼續 switch (v.getId()){ case R.id.get_code: reGetCode.setVisibility(View.GONE); timer.schedule(task, 1000, 1000); // timeTask break; } }}

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

標簽: Android
相關文章:
主站蜘蛛池模板: 国产女主播一二三区丝袜美腿 | 国产成人毛片视频不卡在线 | 九九久久久久久久爱 | 国产一级特黄aa大片软件 | 久久久国产精品va麻豆 | 色婷婷综合激情 | 综合欧美一区二区三区 | 伊人色综合琪琪久久社区 | 亚洲欧美一区二区久久香蕉 | 91久久精品午夜一区二区 | 欧美一级做a爰片久毛片潮 欧美一级做a爰片免费 | 小明看片成人永久在线观看 | 国产亚洲精品日韩综合网 | 久久精品国产国产精品四凭 | a级毛片在线视频免费观看 a级毛片在线播放 | 国产淫片 | 亚洲国产精久久久久久久春色 | 99爱精品视频 | 黄在线视频播放免费网站 | 在线免费观看小视频 | 欧美性色黄大片一级毛片视频 | 中日韩精品视频在线观看 | 色综合综合在线 | 深夜释放自己黄瓜视频 | 免费看色视频 | 国产精品自拍在线 | 国产精品极品美女自在线看免费一区二区 | 国产老湿机福利视频在线观看 | 999精品视频在线 | 92香蕉视频 | 国产免费高清在线精品一区 | 国产成人经典三级在线观看 | 久久99精品久久久久久黑人 | 亚洲图片二区 | 亚洲精品一区二区乱码在线观看 | 欧美区一区 | 妞干网手机免费视频 | 91短视频免费观看 | 看全色黄大色大片免费久黄久 | 国产无限资源在线观看 | 97在线视频99播放 |