Comments (2)
自己重写了一个,建议CountDownButton开放startCountDown方法
package com.wsy.companypassword.view;
import android.content.Context;
import android.os.Handler;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;
/**
* @author cll
* @Time 2019/5/13 16:12
* @Description 倒计时button
*/
public class CountDownButton extends AppCompatButton {
private long totalTime = 60 * 1000;// 默认60秒
private String label = "s";
private long time;
private long step = 1000;
private int interval = 1000;
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
time -= step;
if (time <= 0) {
reset();
}
else {
refreshText();
mHandler.sendEmptyMessageDelayed(0, step);
}
}
};
public CountDownButton(Context context) {
this(context, null);
}
public CountDownButton(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setHintTextColor(getTextColors());
}
public void start() {
this.setEnabled(false);
this.time = totalTime;
refreshText();
mHandler.sendEmptyMessageDelayed(0, step);
}
private void refreshText() {
long t = (time / interval);
if (t > 0) {
this.setText(t + label);
}
}
public void reset() {
setText("获取验证码");
setEnabled(true);
}
/**
* Set count down total time
* <p>
* <code> setTotalTime(30000);// 30s</code>
* </p>
*
* @param totalTime
*
* @return CountDownButton self
*/
public CountDownButton setTotalTime(long totalTime) {
this.totalTime = totalTime;
return this;
}
/**
* Set count down step
* <p>
* <code> setStep(1000);// 1s</code>
* </p>
*
* @param step count down step, micro seconds
*
* @return CountDownButton self
*/
public CountDownButton setStep(long step) {
if (step > 0) {
this.step = step;
}
return this;
}
/**
* Set count down text refresh interval.
* <p>
* <code> setInterval(1000);//1s, text display: (getRemainingTime() / interval) + label</code>
* </p>
*
* @param interval count down text refresh interval, micro seconds
*
* @return CountDownButton self
*/
public CountDownButton setInterval(int interval) {
if (interval > 0) {
this.interval = interval;
}
return this;
}
public long getRemainingTime() {
return time;
}
public long getStep() {
return step;
}
}
from xui.
看你的描述,我建议你使用CountDownButtonHelper,这样更灵活些
from xui.
Related Issues (20)
- SwitchButton的style不生效 HOT 4
- 希望增加一个树形控件。 HOT 1
- 如何用java 动态创建ButtonView 呢? HOT 1
- SuperTextView 支持 setDividerLineColor HOT 1
- XUICommonListItemView 无法修改背景色(实现暗黑模式) HOT 1
- 编译不通过 HOT 2
- 1.1.0版本无法下载依赖 HOT 1
- MaterialDialog自定义view有输入框时无法自动隐藏键盘问题 HOT 1
- 使用RoundButton时无发正常预览 HOT 1
- toast
- 标题栏使用无效的问题 HOT 1
- 新建的项目引入主题报错。 HOT 2
- SuperTextView的sShapeCornersRadius属性失效 HOT 1
- 如何让界面最下面的组件,工具,拓展三个Tab选项一直显示 HOT 1
- 混淆打release包,“shrinkResources true ” 报错:Unable to locate resourceFile : xui_default_flow_tag_bg_rect_round.xml HOT 3
- 动态生成XRangeSlider实例并添加至Linearlayout时触发空指针 HOT 1
- 为什么你的app的拓展部分的代码,很难找呢? HOT 1
- 运行sample,发现在个人中心这个返回按键,一直按不了,触屏无效。最后只能通过手机的返回按钮来返回。 HOT 1
- 自定义dialog customView后怎么获取到布局里面的view? HOT 1
- io.github.inflationx:viewpump between versions 2.0.3 and 1.0.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xui.