Android账号注册实现点击获取验证码倒计时效果
作者:Gxs丶小宇 发布时间:2023-05-18 05:46:33
标签: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>


猜你喜欢
- 一、return语句执行顺序finally语句是在return语句执行之后,return语句返回之前执行的package exception
- kk-anti-reptile 是适用于基于 spring-boot 开发的分布式系统的反爬虫组件。系统要求基于 spring-boot 开
- 说到关注功能,可能很多小伙伴要说了。谁不会写但是没有合理的架构,大家写出来的代码很可能是一大堆的复制粘贴。比如十几个页面,都有这个关注按钮。
- MyBatis缓存我们知道,频繁的数据库操作是非常耗费性能的(主要是因为对于DB而言,数据是持久化在磁盘中的,因此查询操作需要通过IO,IO
- 一、准备工作mybatis-plus作为mybatis的增强工具,它的出现极大的简化了开发中的数据库操作,但是长久以来,它的联表查询能力一直
- 目录为什么要用Geometry数据做图标?怎么获取Geometry数据?如何使用Geometry数据相信大家在阅读WPF相关GitHub开源
- 本文实例汇总了C#面试常见的算法题及其解答。具有不错的学习借鉴价值。分享给大家供大家参考。具体如下:1.写出冒泡,选择,插入排序算法。 &n
- Spring session 获取当前账户登录数一、登录校验成功时,向session加入关键信息,代码如下:session.setAttri
- 1.问题分析我们在开发中经常遇到多个实体类有共同的属性字段,例如在用户注册时需要设置创建时间、创建人、修改时间、修改人等字段,在用户编辑信息
- 缘起标准的RABC, 权限需要支持动态配置,spring security默认是在代码里约定好权限,真实的业务场景通常需要可以支持动态配置角
- 淘宝返回的数据为:{"code":0,"data":{"country":&qu
- 什么是队列结构一种线性结构,具有特殊的运算法则【只能在一端(队头)删除,在另一端(队尾)插入】。分类:顺序队列结构链式队列结构基本操作:入队
- 本文实例为大家分享了RecyclerView实现点击条目删除的具体代码,供大家参考,具体内容如下MainActivity.javapubli
- 1:首先我们看一下数据库的表:这里的pid就是代表他的父节点id,如果没有父节点,那么pid就是0,上面的表就可以看作是一个tree结构,那
- 一、导入和导出导入:通过解析excel表格中的数据,然后将数据放到一个集合中,接着通过对持久层操作,将数据插入到数据库中,再加载一下页面,从
- 通常,反射用于动态获取对象的类型、属性和方法等信息。今天带你玩转反射,来汇总一下反射的各种常见操作,捡漏看看有没有你不知道的。获取类型的成员
- 基础知识介绍: @RequestBody主要用来接收前端传递给后端的json字符串中的
- 动态规划的基本思想是将待求解问题分解成若干个子问题,先求解子问题,并将这些子问题的解保存起来,如果以后在求解较大子问题的时候需要用到这些子问
- 本文介绍了Android:利用SharedPreferences实现自动登录,具体如下:主要代码:public class LoginAct
- 本文实例讲述了Android控件之ListView用法。分享给大家供大家参考。具体如下:示例一:在android开发中ListView是比较