发送手机验证码工具类
来源:互联网 发布:淘宝上哪家卖玉的店铺 编辑:程序博客网 时间:2024/05/19 06:35
之前手机验证码倒计时,写的有bug。现在好了有一个类可以做到。
package com.visoport.medicine.util;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;
import com.visoport.medicine.R;
/**
* 发送手机验证码工具类
*/
public class CountDownTimerUtils extends CountDownTimer {
private TextView mTextView;
/**
* @param textView The TextView
*
*
* @param millisInFuture The number of millis in the future from the call
* to {@link #start()} until the countdown is done and {@link #onFinish()}
* is called.
* @param countDownInterval The interval along the way to receiver
* {@link #onTick(long)} callbacks.
*/
public CountDownTimerUtils(TextView textView, long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
this.mTextView = textView;
}
@Override
public void onTick(long millisUntilFinished) {
mTextView.setClickable(false); //设置不可点击
mTextView.setText(millisUntilFinished / 1000 + "秒后可重新发送"); //设置倒计时时间
mTextView.setBackgroundResource(R.color.white); //设置按钮为灰色,这时是不能点击的
/**
* 超链接 URLSpan
* 文字背景颜色 BackgroundColorSpan
* 文字颜色 ForegroundColorSpan
* 字体大小 AbsoluteSizeSpan
* 粗体、斜体 StyleSpan
* 删除线 StrikethroughSpan
* 下划线 UnderlineSpan
* 图片 ImageSpan
* http://blog.csdn.net/ah200614435/article/details/7914459
*/
SpannableString spannableString = new SpannableString(mTextView.getText().toString()); //获取按钮上的文字
ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);
/**
* public void setSpan(Object what, int start, int end, int flags) {
* 主要是start跟end,start是起始位置,无论中英文,都算一个。
* 从0开始计算起。end是结束位置,所以处理的文字,包含开始位置,但不包含结束位置。
*/
spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//将倒计时的时间设置为红色
mTextView.setText(spannableString);
}
@Override
public void onFinish() {
mTextView.setText("重新获取验证码");
mTextView.setClickable(true);//重新获得点击
mTextView.setBackgroundResource(R.color.gray); //还原背景色
}
}
使用的话,可以
//短信验证码倒计时CountDownTimerUtils count = new CountDownTimerUtils(iv_getCheckkey, 60000, 1000);count.start();
希望这个可以帮到大家。
- 发送手机验证码工具类
- 利用线程创建发送手机验证码的工具类
- 发送手机验证码倒计时
- 给手机发送验证码
- java发送手机验证码
- 手机发送验证码—.net代码
- 用户登录,实现发送手机验证码。
- js jq手机验证码发送
- java功能模块--给手机发送验证码
- button倒计时,发送手机验证码可用
- java给手机发送验证码思路
- 手机验证码发送(ThinkPHP)
- laravel框架手机发送验证码
- java实现手机发送验证码
- pc端向手机发送验证码
- SMSSDK第三方发送手机验证码
- js实现手机验证码发送
- java实现发送手机验证码
- Linux中TCP listen()的参数
- Java8源码-Stack
- 概率基础1-事件与概率
- 将从数据库中获取的数据写入到Excel表中
- Spring中的配置类
- 发送手机验证码工具类
- HDU 6078 Wavel Sequence【动态规划】
- MFC+opencv遇到的问题汇总
- Android Studio导入第三方java类库含源代码包
- java集合之HashMap
- BZOJ 2243: [SDOI2011]染色 树链剖分 区间合并
- this和 $(this)的区别
- less-loader、css-loader、style-loader
- Unity3D利用Photon实现实时联网对战(一)Photon Sever介绍