在我们注册或者修改信息的时候,常会用到60s倒计时这个功能,写了这篇文章,大家共享一下:
效果图:
直接上代码:
activity.java
public class MainActivity extends Activity { private TimeCount mTiemTimeCount; private TextView tv_code; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTiemTimeCount = new TimeCount(60000, 1000); initView(); } private void initView() { // TODO Auto-generated method stub tv_code = (TextView) findViewById(R.id.verify_code); tv_code.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mTiemTimeCount.start(); } }); } // 计时重发 private class TimeCount extends CountDownTimer { public TimeCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } @Override public void onTick(long millisUntilFinished) { tv_code.setClickable(false); tv_code.setText(millisUntilFinished / 1000 + "秒后重新发送"); } @Override public void onFinish() { tv_code.setText("获取验证码"); tv_code.setClickable(true); } } @Override protected void onDestroy() { super.onDestroy(); mTiemTimeCount.cancel(); } }
mTiemTimeCount = new TimeCount(60000, 1000);可以自己更改时间
相关推荐
大神勿喷,该资源就是一个小程序获取验证码倒计时,很简单
安卓发送验证码倒计时效果和自动获取验证码并填充到输入框
react-验证码倒计时组件
这个是一个验证码倒计时的自定义控件,直接使用就可以实现计时功能。
jquery验证码倒计时
jQuery表单验证与表单美化手机发送验证码倒计时插件
js短信验证码倒计时(页面刷新无效)
android一句代码实现发送验证码倒计时
Android 验证码倒计时AS注册、重置密码获取验证码
JQ实现手机验证码倒计时,用的时候只要引入JQ文件就行,attr和removeAttr中的class可以根据需求去除.doc
vueJS+bootstrap+html5验证码倒计时.
一个简单的获取验证码倒计时控件的封装,方便自己日常调用。
一句话搞定发送验证码倒计时
使用了CountdownTimer实现短信验证码倒计时的效果,并解决了倒计时读数不准确的Bug。博客地址:http://blog.csdn.net/Lindroid20/article/details/73693102
ios按钮自定义,扩大响应范围,设置部分圆角,发送验证码倒计时
发送验证码倒计时,前端js,发送验证码倒计时代码,发送验证码倒计时代码。
验证码倒计时
采用GCD的方式来写的,因为GCD这种方式的倒计时要比NStimer的精准的多
小功能短信倒计时,目前写在了php文件中,有不明白的可以联系我
通过CountDownTimer实现验证码倒计时效果,通过CountDownTimer实现验证码倒计时效果