Android倒计时

来源:互联网 发布:淘宝网图片保护入口 编辑:程序博客网 时间:2024/05/22 00:34
    /**     * 短信倒计时     */    int                time    = 61; //倒计时初始时间    android.os.Handler handler = new android.os.Handler();    private void reverseTime() {        handler.postDelayed(new Runnable() {            @Override            public void run() {                time--;                //倒计时按钮不可用                tvCheckcode.setEnabled(false);                //倒计时字体颜色                tvCheckcode.setTextColor(Color.BLACK);                //倒计时time秒                tvCheckcode.setText("剩余时间:" + time + "s)");                if (time >= 0) {                    handler.postDelayed(this, 1000);                } else {                    //当倒计时为0秒时,恢复初始状态                    time = 61;                    tvCheckcode.setText("获取验证码");                    tvCheckcode.setEnabled(true);                    tvLoginCheckcode.setTextColor(Color.BLUE);                }            }        }, 1000);    }

0 0