短信倒计时自定义按钮

来源:互联网 发布:python中文注释 编辑:程序博客网 时间:2024/06/03 19:11

Timer

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Description:自定义Timer
 * <p>
 * Created by Mjj on 2016/12/4.
 */
 
public class TimeCount extendsCountDownTimer {
 
  privateButton button;
 
  //参数依次为总时长,和计时的时间间隔
  publicTimeCount(Button button, longmillisInFuture, longcountDownInterval) {
    super(millisInFuture, countDownInterval);
    this.button = button;
  }
 
  //计时过程显示
  @Override
  publicvoid onTick(longmillisUntilFinished) {
    String time ="(" + millisUntilFinished /1000 + ")秒";
    setButtonInfo(time,"#c1c1c1", false);
  }
 
  //计时完毕时触发
  @Override
  publicvoid onFinish() {
    setButtonInfo("重新获取","#f95353", true);
  }
 
  /**
   * 验证按钮在点击前后相关设置
   *
   * @param content 要显示的内容
   * @param color  颜色值
   * @param isClick 是否可点击
   */
  privatevoid setButtonInfo(String content, String color,boolean isClick) {
    button.setText(content);
    button.setBackgroundColor(Color.parseColor(color));
    button.setClickable(isClick);
  }
}

说明:根据自己的需求,在这里修改背景颜色和不同状态显示文字即可,在需要监听的按钮下直接调用new TimerCount(xxx,xxx,xxx).start()即可。

0 0
原创粉丝点击