Android 文章

android倒计时类的使用

2018-08-15  本文已影响32人  爱在记忆消失前

package com.njsoft.jcyy.activity;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.njsoft.jcyy.R;
import com.njsoft.jcyy.mvp.TopBarBaseActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**

@BindView(R.id.Register_phone)
EditText RegisterPhone;
@BindView(R.id.Register_EditCode)
EditText RegisterEditCode;
@BindView(R.id.Register_Code)
TextView RegisterCode;
@BindView(R.id.Register_Password)
EditText RegisterPassword;
@BindView(R.id.Register_PWShow)
ImageView RegisterPWShow;
@BindView(R.id.Regisiter_Confirm)
Button RegisiterConfirm;
@BindView(R.id.Register_Rules)
TextView RegisterRules;
private boolean PasswordState = false;//密码状态

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);
}

@Override
protected int getContentView() {
    return R.layout.activity_register;
}

@Override
protected void init(Bundle savedInstanceState) {
    setTitle("手机号快速注册");
    setTopLeftButton();
}


CountDownTimer timer = new CountDownTimer(60 * 1000, 1000) {
    @Override
    public void onTick(long millisUntilFinished) {
        RegisterCode.setText("还剩" + millisUntilFinished / 1000 + "秒");
    }

    @Override
    public void onFinish() {
        RegisterCode.setText("重新发送");
        RegisterCode.setClickable(true);
    }
};

@Override
protected void onDestroy() {
    super.onDestroy();
    timer.cancel();
}

@OnClick({R.id.Register_PWShow, R.id.Register_Code, R.id.Regisiter_Confirm, R.id.Register_Rules})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.Register_Code:
          //开始计时
            timer.start();
            RegisterCode.setClickable(false);
            break;
        case R.id.Regisiter_Confirm:
            break;
        case R.id.Register_Rules:
            break;
        case R.id.Register_PWShow:
            PasswordState=!PasswordState;
            if (PasswordState) {
                RegisterPWShow.setImageResource(R.mipmap.login_open_eyes);//睁眼
                RegisterPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            }else {
                RegisterPWShow.setImageResource(R.mipmap.login_close_eyes);//闭眼
                RegisterPassword.setInputType(InputType.TYPE_CLASS_TEXT | 
                      InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
            break;
    }
}

}

上一篇下一篇

猜你喜欢

热点阅读