美文网首页
android 获取验证码

android 获取验证码

作者: 小婷婷tt | 来源:发表于2018-05-17 14:29 被阅读0次

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);

}

}

相关文章

网友评论

      本文标题:android 获取验证码

      本文链接:https://www.haomeiwen.com/subject/grubdftx.html