Android账号注册实现点击获取验证码倒计时效果

网站中为了防止恶意获取验证短信、验证邮箱,都会在点击获取验证码的按钮上做个倒计时的效果,如何实现这个效果,具体内容如下

效果图:

代码:

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,"倒计时结束",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>

以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持脚本之家。

时间: 2024-07-29 19:58:16

Android账号注册实现点击获取验证码倒计时效果的相关文章

Android账号注册实现点击获取验证码倒计时效果_Android

网站中为了防止恶意获取验证短信.验证邮箱,都会在点击获取验证码的按钮上做个倒计时的效果,如何实现这个效果,具体内容如下 效果图:   代码: RegisterActivity.java import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import com.jialianjia.bzw.BaseAct

js实现点击获取验证码倒计时效果_javascript技巧

网站中为了防止恶意获取验证短信.验证邮箱,都会在点击获取验证码的按钮上做个倒计时的效果.实现这个功能,一个setInterval和一个clearInterval就能搞定了,不需要太多的代码.实例效果和代码如下: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <input type="button" style="height:

Andorid实现点击获取验证码倒计时效果_Android

我们在开发中经常用到倒计时的功能,比如发送验证码后,倒计时60s再进行验证码的获取,为了方便以后使用,这里做个记录,讲讲倒计时器的实现.  1.先进行倒计时工具类的封装  public class CountDownTimerUtils extends CountDownTimer { private TextView mTextView; /** * @param textView The TextView * * * @param millisInFuture The number of m

Andorid实现点击获取验证码倒计时效果

我们在开发中经常用到倒计时的功能,比如发送验证码后,倒计时60s再进行验证码的获取,为了方便以后使用,这里做个记录,讲讲倒计时器的实现. 1.先进行倒计时工具类的封装 public class CountDownTimerUtils extends CountDownTimer { private TextView mTextView; /** * @param textView The TextView * * * @param millisInFuture The number of mil

iOS获取验证码倒计时效果_IOS

本文实例为大家分享了iOS倒计时获取验证码的具体代码,供大家参考,具体内容如下 1. 倒计时发送验证码,界面跳转计时会重置 /**重新发送短信的计时*/ -(void)fireTimer{ __block int timeout=180; //倒计时时间 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t _timer = dispatc

Android获取验证码倒计时显示效果_Android

前面为大家讲过计时器的顺时针的两种方法,在录制视频等操作中颇有使用,今天就给大家带来倒计时实现的两种方式. 虽然最近写的都比较简单和基础,不过简单不代表熟悉,基础不代表就会,大牛绕过,哈,中牛小牛也可以绕过,这个是写给初学者的. 先搞个效果图. 代码实现方式也超级简单啦,这里首推第一种实现方式,而且也是比较适合大家的,就是通过直接继承CountDownTimer来实现. 对于CountDownTimer这个类很简单,继承它的时候必须重写构造方法和实现其虚拟方法. 构造方法的两个参数分别是(倒计时

Android手机号注册、绑定手机号获取短信验证码实例_Android

本文写了一个常见的功能--手机app中注册或绑定手机号的获取验证码的功能,也就是短信验证功能 具体效果就是,你在注册界面填写手机号,点击获取验证码按钮,---然后会收到验证短信,填入验证码后点击注册按钮,如果验证正确就可以跳转到另外一个界面 1.首先大家需要在mob官网注册一个账号,mob是一个免费的短信验证平台 2.在mob.com后台创建应用 3.下载对应的sdk 4.将sdk作为一个library导入到你的项目中 5.现在就可以在你的项目中编写代码使用mob提供的这个功能了 具体代码如下:

Android手机号注册、绑定手机号获取短信验证码实例

本文写了一个常见的功能--手机app中注册或绑定手机号的获取验证码的功能,也就是短信验证功能 具体效果就是,你在注册界面填写手机号,点击获取验证码按钮,---然后会收到验证短信,填入验证码后点击注册按钮,如果验证正确就可以跳转到另外一个界面 1.首先大家需要在mob官网注册一个账号,mob是一个免费的短信验证平台 2.在mob.com后台创建应用 3.下载对应的sdk 4.将sdk作为一个library导入到你的项目中 5.现在就可以在你的项目中编写代码使用mob提供的这个功能了 具体代码如下:

Jquery插件实现点击获取验证码后60秒内禁止重新获取

 这篇文章主要介绍了Jquery插件实现点击获取验证码后60秒内禁止重新获取,十分常用的功能,这里分享给大家,有需要的小伙伴参考下吧.     通过jquery.cookie.js插件可以快速实现"点击获取验证码后60秒内禁止重新获取(防刷新)"的功能 效果图: 先到官网(http://plugins.jquery.com/cookie/)下载cookie插件,放到相应文件夹,代码如下:   代码如下: <!DOCTYPE html> <html> <he