Android賬號注冊實現(xiàn)點擊獲取驗證碼倒計時效果
更新時間:2016年05月25日 11:58:13 作者:Gxs丶小宇
這篇文章主要為大家詳細介紹了Android賬號注冊過程中實現(xiàn)點擊獲取驗證碼倒計時效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
網(wǎng)站中為了防止惡意獲取驗證短信、驗證郵箱,都會在點擊獲取驗證碼的按鈕上做個倒計時的效果,如何實現(xiàn)這個效果,具體內(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); // 獲取驗證碼--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,"倒計時",60,1); helper.setOnFinishListener(new CountDownButtonHelper.OnFinishListener() { @Override public void finish() { // Toast.makeText(RegisterActivity.this,"倒計時結(jié)束",Toast.LENGTH_SHORT).show(); btn_yzm.setText("再次獲取"); } }); helper.start(); } }); // 獲取驗證碼--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)容,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android實現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器
這篇文章主要介紹了Android實現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08Android入門之使用SQLite內(nèi)嵌式數(shù)據(jù)庫詳解
Android內(nèi)帶SQLite內(nèi)嵌式數(shù)據(jù)庫了。這對于我們存儲一些更復(fù)雜的結(jié)構(gòu)化數(shù)據(jù)帶來了極大的便利。本文就來和大家聊聊具體的使用方法,希望對大家有所幫助2022-12-12android.enableD8.desugaring?=?false引發(fā)問題解決
這篇文章主要為大家介紹了android.enableD8.desugaring?=?false引發(fā)問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03