1.如圖所示,要實現(xiàn)一個驗證碼的倒計時的效果
	 
  
  
                     
2.實現(xiàn)
圖中獲取驗證碼那塊是一個button按鈕
關(guān)鍵部分,聲明一個TimeCount,繼承自CountDownTimer
/*驗證碼倒計時*/private class TimeCount extends CountDownTimer{  /**   * @param millisInFuture  總時間長度(毫秒)   * @param countDownInterval 時間間隔(毫秒),每經(jīng)過一次時間間隔都會調(diào)用onTick方法   */  public TimeCount(long millisInFuture, long countDownInterval) {    super(millisInFuture, countDownInterval);  }  @Override  public void onTick(long millisUntilFinished) {   //倒計時狀態(tài)    getVerificationCodeBtn.setClickable(false);     //設(shè)置button此時不可點擊    getVerificationCodeBtn.setBackground(getResources().getDrawable(R.drawable.get_verification_code_waitting_bg));//修改button的背景    getVerificationCodeBtn.setTextColor(getResources().getColor(R.color.black));//修改button的textColor    getVerificationCodeBtn.setText(millisUntilFinished / 1000 +"s后可重新發(fā)送");//顯示button的倒計時文字  }  @Override  public void onFinish() {      //倒計時結(jié)束狀態(tài)    getVerificationCodeBtn.setBackground(getResources().getDrawable(R.drawable.login_btn_bg));    getVerificationCodeBtn.setTextColor(getResources().getColor(R.color.white));    getVerificationCodeBtn.setClickable(true);   //重新設(shè)置button為可點擊    getVerificationCodeBtn.setText("重新獲取");   //修改button的文字  }}最后在代碼中,聲明TimeCount并實例化,在button的點擊事件中調(diào)用.start()方法啟動定時器。
TimeCount timeCount = new TimeCount(60000,1000); timeCount.start();
總結(jié)
以上所述是小編給大家介紹的android實現(xiàn)一個圖片驗證碼倒計時功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對VEVB武林網(wǎng)網(wǎng)站的支持!
新聞熱點
疑難解答
圖片精選