Buttonm BtnBindCode;
private CountDownTimer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bind_wallet_validation)
initTimer();
}
/**
* 实例化计时器
*/
private void initTimer() {
timer =new CountDownTimer(60000,1000) {
@Override
public void onTick(long millisUntilFinished) {
mBtnBindCode.setText(millisUntilFinished /1000 +"s");
}
@Override
public void onFinish() {
mBtnBindCode.setEnabled(true);
mBtnBindCode.setBackgroundColor(Color.parseColor("#0088FF"));
mBtnBindCode.setText("重新获取");
}
};
}
@OnClick({R.id.btn_bind_code})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.btn_bind_code:
sendCode(mMobile);
if (timer !=null) {
timer.start();
mBtnBindCode.setEnabled(false);
mBtnBindCode.setBackgroundColor(Color.parseColor("#ACACAC"));
}
break;
}
}
/**
* 重新获取验证码
*/
private void cancelTimer(String msg) {
if (timer !=null) {
timer.cancel();
mBtnBindCode.setEnabled(true);
mBtnBindCode.setBackgroundColor(Color.parseColor("#0088FF"));
mBtnBindCode.setText(msg);
}
}









网友评论