Android賬號(hào)注冊(cè)實(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;
/**
* 注冊(cè)功能
* 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,"賬號(hào)注冊(cè)",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>
以上就是本文的全部?jī)?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) (代碼簡(jiǎn)單)
- Android開發(fā)歡迎頁點(diǎn)擊跳過倒計(jì)時(shí)進(jìn)入主頁
相關(guān)文章
Android中數(shù)據(jù)庫常見操作實(shí)例分析
這篇文章主要介紹了Android中數(shù)據(jù)庫常見操作,以完整實(shí)例形式較為詳細(xì)的分析了Android基于數(shù)據(jù)庫類進(jìn)行數(shù)據(jù)庫的增刪改查等操作技巧,需要的朋友可以參考下2015-10-10
Android中RecyclerView布局代替GridView實(shí)現(xiàn)類似支付寶的界面
RecyclerView比GridView來得更加強(qiáng)大,不僅是在分割線的繪制方面,在條目的編輯上也做得同樣出色,下面就來看一下Android中RecyclerView布局代替GridView實(shí)現(xiàn)類似支付寶的界面的實(shí)例2016-06-06
Android自定義View實(shí)現(xiàn)loading動(dòng)畫加載效果
項(xiàng)目開發(fā)中對(duì)Loading的處理是比較常見的,安卓系統(tǒng)提供的不太美觀,引入第三發(fā)又太麻煩,這時(shí)候自己定義View來實(shí)現(xiàn)這個(gè)效果。這篇文章主要介紹了Android自定義View實(shí)現(xiàn)loading動(dòng)畫加載效果,需要的朋友可以參考下2017-03-03
解析android創(chuàng)建快捷方式會(huì)啟動(dòng)兩個(gè)應(yīng)用的問題
本篇文章是對(duì)關(guān)于android創(chuàng)建快捷方式會(huì)啟動(dòng)兩個(gè)應(yīng)用的問題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Android 使用Path實(shí)現(xiàn)涂鴉功能
到月底了最近比較空閑,今天抽空給大家實(shí)現(xiàn)一個(gè)涂鴉效果,會(huì)分幾步實(shí)現(xiàn),這里有一個(gè)重要的知識(shí)點(diǎn)就是圖層,要理解這個(gè)。下面先從簡(jiǎn)單的說起,一起看看代碼吧2016-12-12
Android 系統(tǒng)服務(wù)TelecomService啟動(dòng)過程原理分析
這篇文章主要介紹了Android 系統(tǒng)服務(wù)TelecomService啟動(dòng)過程原理分析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
android跑馬燈出現(xiàn)重復(fù)跳動(dòng)以及不滾動(dòng)問題的解決方法
這篇文章主要介紹了android跑馬燈出現(xiàn)重復(fù)跳動(dòng)以及不滾動(dòng)問題的解決方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
Android編程實(shí)現(xiàn)設(shè)置TabHost當(dāng)中字體的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)設(shè)置TabHost當(dāng)中字體的方法,涉及Android針對(duì)TabHost屬性操作的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-12-12

