Android "120秒后重新获取"

来源:互联网 发布:苹果电脑可以学c语言吗 编辑:程序博客网 时间:2024/05/16 01:11
public class VerifyCodeCountTimer extends CountDownTimer{        // 时间防止从119s开始显示(以倒计时120s为例子)        public static final int TIME_COUNT = 121000;    private TextView btn;    private String endStrRid;    // 未计时的文字颜色,计时期间的文字颜色    private int normalColor, timingColor;    Context mContext;    public VerifyCodeCountTimer(long millisInFuture, long countDownInterval,TextView btn, String endStrRid) {        super(millisInFuture, countDownInterval);        this.btn = btn;        this.endStrRid = endStrRid;    }        public VerifyCodeCountTimer(Context context, TextView btn, String endStrRid) {        super(TIME_COUNT, 1000);        this.btn = btn;        this.endStrRid = endStrRid;        this.mContext = context;    }    public VerifyCodeCountTimer(TextView btn) {        super(TIME_COUNT, 1000);        this.btn = btn;    }    public VerifyCodeCountTimer(TextView tv_varify, int normalColor,            int timingColor) {        this(tv_varify);        this.normalColor = normalColor;        this.timingColor = timingColor;    }// 计时完毕时触发@Overridepublic void onFinish() {     if (normalColor > 0) {         btn.setTextColor(normalColor);        }        btn.setText(endStrRid);        btn.setEnabled(true);        btn.setBackgroundResource(R.drawable.bg_verify_code);    }    // 计时过程显示    @Override    public void onTick(long millisUntilFinished) {        if (timingColor > 0) {            btn.setTextColor(timingColor);        }        btn.setEnabled(false);        btn.setText(millisUntilFinished / 1000 + "秒后重新获取");        btn.setBackgroundColor(Color.GRAY);    }}
0 0
原创粉丝点击