android 获取短信验证码倒计时
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWVuZ2xlbGUxMzE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" height="382" width="259">
public class MainActivity extends Activity {
private Button submit;
private TimeCount time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
time = new TimeCount(60000, 1000);
submit = (Button) findViewById(R.id.btn_login_submit);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
time.start();// 開始计时
}
});
}
class TimeCount extends CountDownTimer {
public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {// 计时完成
submit.setText("获取验证码");
submit.setClickable(true);
}
@Override
public void onTick(long millisUntilFinished) {// 计时过程
submit.setClickable(false);//防止反复点击
submit.setText(millisUntilFinished / 1000 + "s");
}
}