Android之倒计时实现
来源:互联网 发布:金融大数据应用案例 编辑:程序博客网 时间:2024/06/06 15:04
public class MyCountTimer extends CountDownTimer {
public static final int TIME_COUNT = 121000;//时间防止从119s开始显示(以倒计时120s为例子)
private TextView btn;
private int endStrRid;
private int normalColor, timingColor;//未计时的文字颜色,计时期间的文字颜色s
/**
* 参数 millisInFuture 倒计时总时间(如60S,120s等)
* 参数 countDownInterval 渐变时间(每次倒计1s)
* 参数 btn 点击的按钮(因为Button是TextView子类,为了通用我的参数设置为TextView)
* 参数 endStrRid 倒计时结束后,按钮对应显示的文字
*/
public MyCountTimer (long millisInFuture, long countDownInterval, TextView btn, int endStrRid) {
super(millisInFuture, countDownInterval);
this.btn = btn;
this.endStrRid = endStrRid;
}
/**
*参数上面有注释
*/
public MyCountTimer (TextView btn, int endStrRid) {
super(TIME_COUNT, 1000);
this.btn = btn;
this.endStrRid = endStrRid;
}
public MyCountTimer (TextView btn) {
super(TIME_COUNT, 1000);
this.btn = btn;
this.endStrRid = R.string.txt_getMsgCode_validate;
}
public MyCountTimer (TextView tv_varify, int normalColor, int timingColor) {
this(tv_varify);
this.normalColor = normalColor;
this.timingColor = timingColor;
}
// 计时完毕时触发
@Override
public void onFinish() {
if(normalColor < 0){
btn.setTextColor(normalColor);
}
btn.setText(endStrRid);
btn.setEnabled(true);
}
// 计时过程显示
@Override
public void onTick(long millisUntilFinished) {
if(timingColor < 0){
btn.setTextColor(timingColor);
}
btn.setEnabled(false);
btn.setText(millisUntilFinished / 1000 + "s");
}
}
public static final int TIME_COUNT = 121000;//时间防止从119s开始显示(以倒计时120s为例子)
private TextView btn;
private int endStrRid;
private int normalColor, timingColor;//未计时的文字颜色,计时期间的文字颜色s
/**
* 参数 millisInFuture 倒计时总时间(如60S,120s等)
* 参数 countDownInterval 渐变时间(每次倒计1s)
* 参数 btn 点击的按钮(因为Button是TextView子类,为了通用我的参数设置为TextView)
* 参数 endStrRid 倒计时结束后,按钮对应显示的文字
*/
public MyCountTimer (long millisInFuture, long countDownInterval, TextView btn, int endStrRid) {
super(millisInFuture, countDownInterval);
this.btn = btn;
this.endStrRid = endStrRid;
}
/**
*参数上面有注释
*/
public MyCountTimer (TextView btn, int endStrRid) {
super(TIME_COUNT, 1000);
this.btn = btn;
this.endStrRid = endStrRid;
}
public MyCountTimer (TextView btn) {
super(TIME_COUNT, 1000);
this.btn = btn;
this.endStrRid = R.string.txt_getMsgCode_validate;
}
public MyCountTimer (TextView tv_varify, int normalColor, int timingColor) {
this(tv_varify);
this.normalColor = normalColor;
this.timingColor = timingColor;
}
// 计时完毕时触发
@Override
public void onFinish() {
if(normalColor < 0){
btn.setTextColor(normalColor);
}
btn.setText(endStrRid);
btn.setEnabled(true);
}
// 计时过程显示
@Override
public void onTick(long millisUntilFinished) {
if(timingColor < 0){
btn.setTextColor(timingColor);
}
btn.setEnabled(false);
btn.setText(millisUntilFinished / 1000 + "s");
}
}
0 0
- Android之倒计时实现
- Android之实现倒计时
- Android实现倒计时之使用CountDownTimer
- Android实现倒计时之使用CountDownTimer
- android 开发之- 获取倒计时CountDownTimer 实现
- android 实现倒计时
- Android 倒计时的实现
- android 实现倒计时功能
- Android -- 倒计时的实现
- Android倒计时简单实现
- Android CountDownTimer 倒计时实现
- android 倒计时实现
- android handle实现倒计时
- Android倒计时功能实现
- Android中倒计时实现
- 简单Android倒计时实现
- android 倒计时实现
- Android快速实现倒计时
- ios开发---音乐播放器之怎么获取音乐列表
- 百度地图最简单的完成接口,和实例代码
- C++面向对象操作符重载:输入输出操作符
- 因为我们是OIER
- fragment获取context
- Android之倒计时实现
- hdu4452 搜索模拟 Running Rabbits (2012 Asia JinHua Regional Contest problem K)
- Python联系人(添、删、查、改)
- 她生病了,可我却不能陪伴在身边
- DOxygen for C++使用说明——添加数学公式
- 关于The import android.support.v7.app cannot be resolved
- myeclipse部署maven时,src/main/resources里面配置文件加载不到webapp下classes路径下的问题 分类: Maven Myeclipse 2014-07-11 1
- Fedora23安装以后要做的优化配置
- js内如何导入jason文件及从做好的文件内获取输入框信息,以及离子特效文件