Android系統自帶的一個倒計時類,可作為驗證碼倒計時等。


public class TimeCount extends CountDownTimer {
private static final int TIME_TASCK = 1000;
private Button button;
private Context context;
public TimeCount(Context context, long millisInFuture, Button view) {
super(millisInFuture, TIME_TASCK);
button = view;
this.context = context;
}

@Override
public void onFinish() {// 計時完畢
button.setTextColor(context.getResources().getColor(R.color.text_white));
button.setBackgroundResource(R.drawable.button_background);
button.setText("發送驗證碼");
button.setClickable(true);
}

@Override
public void onTick(long millisUntilFinished) {// 計時過程
button.setTextColor(context.getResources().getColor(R.color.home_item_count));
button.setClickable(false);//防止重復點擊
button.setBackgroundResource(R.drawable.gray_button_background);
button.setText(context.getString(R.string.send_count_down, millisUntilFinished / TIME_TASCK));
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM