Android賬號注冊實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
網(wǎng)站中為了防止惡意獲取驗(yàn)證短信、驗(yàn)證郵箱,都會(huì)在點(diǎn)擊獲取驗(yàn)證碼的按鈕上做個(gè)倒計(jì)時(shí)的效果,如何實(shí)現(xiàn)這個(gè)效果,具體內(nèi)容如下
效果圖:
代碼:
RegisterActivity.java
import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import com.jialianjia.bzw.BaseActivity; import com.jialianjia.bzw.R; import com.jialianjia.bzw.utils.CountDownButtonHelper; import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.view.annotation.ViewInject; /** * 注冊功能 * Created by GXS on 2016/4/21. */ public class RegisterActivity extends BaseActivity{ private Button btn_yzm; @ViewInject(R.id.toolbar) Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); ViewUtils.inject(this); initToolBar(toolbar,"賬號注冊",true); // 獲取驗(yàn)證碼--start btn_yzm = (Button) findViewById(R.id.btn_yzm); btn_yzm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CountDownButtonHelper helper = new CountDownButtonHelper(btn_yzm,"倒計(jì)時(shí)",60,1); helper.setOnFinishListener(new CountDownButtonHelper.OnFinishListener() { @Override public void finish() { // Toast.makeText(RegisterActivity.this,"倒計(jì)時(shí)結(jié)束",Toast.LENGTH_SHORT).show(); btn_yzm.setText("再次獲取"); } }); helper.start(); } }); // 獲取驗(yàn)證碼--end } }
布局文件:
activity_register.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"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:theme="@style/AppTheme.AppBarOverlay" android:fitsSystemWindows="true" /> <LinearLayout android:layout_height="50dp" android:layout_width="match_parent" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:background="@color/white" android:orientation="horizontal"> <TextView android:id="@+id/tv_phone" android:layout_width="60dp" android:layout_height="wrap_content" android:text="@string/tv_info_phone" android:layout_margin="8dp" android:textColor="@color/black" android:layout_gravity="center_vertical" android:textSize="17sp"/> <EditText android:id="@+id/et_phone" android:layout_width="190dp" android:layout_height="35dp" android:layout_toRightOf="@id/tv_phone" android:background="@null" android:hint="@string/edt_phone_tips" android:maxLength="20" android:layout_gravity="center_vertical" android:singleLine="true" android:textSize="16sp" /> <View android:layout_width="2px" android:layout_height="50dp" android:background="@color/driverline" /> <Button android:id="@+id/btn_yzm" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_marginLeft="3dp" android:layout_gravity="center" android:background="@color/white" android:text="@string/btn_yzm_text"/> </LinearLayout> <View android:id="@+id/view_line" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/tv_phone" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@color/driverline" /> <LinearLayout android:layout_height="50dp" android:layout_width="match_parent" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:background="@color/white" android:orientation="horizontal"> <TextView android:id="@+id/tv_yzm" android:layout_width="60dp" android:layout_height="wrap_content" android:text="@string/tv_yzm_text" android:layout_margin="8dp" android:textColor="@color/black" android:layout_gravity="center_vertical" android:textSize="17sp"/> <EditText android:id="@+id/et_yzm" android:layout_width="190dp" android:layout_height="35dp" android:layout_toRightOf="@id/tv_phone" android:background="@null" android:hint="@string/edt_yzm_tips" android:maxLength="20" android:layout_gravity="center_vertical" android:singleLine="true" android:textSize="16sp" /> </LinearLayout> <View android:id="@+id/view_line1" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/tv_phone" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@color/driverline" /> <LinearLayout android:layout_height="50dp" android:layout_width="match_parent" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:background="@color/white" android:orientation="horizontal"> <TextView android:id="@+id/tv_password" android:layout_width="60dp" android:layout_height="wrap_content" android:text="@string/tv_password_text" android:layout_margin="8dp" android:textColor="@color/black" android:layout_gravity="center_vertical" android:textSize="17sp"/> <EditText android:id="@+id/et_password" android:layout_width="190dp" android:layout_height="35dp" android:layout_toRightOf="@id/tv_phone" android:background="@null" android:hint="@string/edt_password_text" android:maxLength="20" android:layout_gravity="center_vertical" android:singleLine="true" android:textSize="16sp" /> </LinearLayout> <View android:id="@+id/view_line2" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/tv_phone" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@color/driverline" /> <Button android:id="@+id/btn_regist" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/btn_select" android:gravity="center" android:padding="5dp" android:text="@string/btn_regist_text" android:textColor="@color/white" android:textSize="16sp" /> </LinearLayout>
以上就是本文的全部內(nèi)容,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Android利用CountDownTimer實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
- Android實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
- Android中TextView實(shí)現(xiàn)部分文字可點(diǎn)擊跳轉(zhuǎn)
- Android studio點(diǎn)擊跳轉(zhuǎn)WebView詳解
- Android中TextView自動(dòng)識(shí)別url且實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)
- Android TextView中文本點(diǎn)擊文字跳轉(zhuǎn) (代碼簡單)
- Android開發(fā)歡迎頁點(diǎn)擊跳過倒計(jì)時(shí)進(jìn)入主頁
相關(guān)文章
Android實(shí)現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器
這篇文章主要介紹了Android實(shí)現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08Android 后臺(tái)調(diào)度任務(wù)與省電詳解
本文主要介紹 Android 后臺(tái)調(diào)度任務(wù)與省電,這里整理了詳細(xì)的知識(shí)資料供大家學(xué)習(xí)參考,希望能幫助有需要的小伙伴2016-08-08Android用于校驗(yàn)集合參數(shù)的小封裝示例
本篇文章主要介紹了Android-用于校驗(yàn)集合參數(shù)的小封裝示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10Android入門之使用SQLite內(nèi)嵌式數(shù)據(jù)庫詳解
Android內(nèi)帶SQLite內(nèi)嵌式數(shù)據(jù)庫了。這對于我們存儲(chǔ)一些更復(fù)雜的結(jié)構(gòu)化數(shù)據(jù)帶來了極大的便利。本文就來和大家聊聊具體的使用方法,希望對大家有所幫助2022-12-12Android模仿美團(tuán)頂部的滑動(dòng)菜單實(shí)例代碼
最近在工作遇到一個(gè)需要,要做一個(gè)滑動(dòng)菜單,實(shí)現(xiàn)的效果類似美團(tuán)頂部的滑動(dòng)菜單,所以下面這篇文章主要給大家介紹了關(guān)于Android如何模仿美團(tuán)頂部滑動(dòng)菜單的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08android.enableD8.desugaring?=?false引發(fā)問題解決
這篇文章主要為大家介紹了android.enableD8.desugaring?=?false引發(fā)問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03Android中傳遞對象的三種方法的實(shí)現(xiàn)
本篇文章主要介紹了Android中傳遞對象的三種方法的實(shí)現(xiàn),可以通過Bundle、Intent或者JSON字符串,有興趣的可以了解一下。2017-02-02