倒计时
-
public class MainActivity extends Activity {
-
private TimeCount time;
-
private Button btnGetcode;
-
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.activity_main);
-
time = new TimeCount( 60000, 1000);
-
btnGetcode=(Button) findViewById(R.id.btn_getcode);
-
btnGetcode.setOnClickListener( new OnClickListener() {
-
-
-
public void onClick(View v) {
-
time.start();
-
}
-
});
-
}
-
class TimeCount extends CountDownTimer {
-
-
public TimeCount(long millisInFuture, long countDownInterval) {
-
super(millisInFuture, countDownInterval);
-
}
-
-
-
public void onTick(long millisUntilFinished) {
-
btnGetcode.setBackgroundColor(Color.parseColor( "#ffffff"));
-
btnGetcode.setClickable( false);
-
btnGetcode.setText( "("+millisUntilFinished / 1000 + ") 秒后可重新发送");
-
}
-
-
-
public void onFinish() {
-
btnGetcode.setText( "重新获取验证码");
-
btnGetcode.setClickable( true);
-
btnGetcode.setBackgroundColor(Color.parseColor( "#ef8a34"));
-
-
}
-
}
-
}