亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android實(shí)現(xiàn)一個(gè)圖片驗(yàn)證碼倒計(jì)時(shí)功能

 更新時(shí)間:2017年11月07日 10:13:08   作者:卡夫卡15  
本文通過實(shí)例代碼給大家介紹了android實(shí)現(xiàn)一個(gè)圖片驗(yàn)證碼倒計(jì)時(shí)功能,代碼簡單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

1.如圖所示,要實(shí)現(xiàn)一個(gè)驗(yàn)證碼的倒計(jì)時(shí)的效果      

                       

2.實(shí)現(xiàn)

  圖中獲取驗(yàn)證碼那塊是一個(gè)button按鈕

  關(guān)鍵部分,聲明一個(gè)TimeCount,繼承自CountDownTimer

/*驗(yàn)證碼倒計(jì)時(shí)*/
private class TimeCount extends CountDownTimer{
  /**
   * @param millisInFuture  總時(shí)間長度(毫秒)
   * @param countDownInterval 時(shí)間間隔(毫秒),每經(jīng)過一次時(shí)間間隔都會(huì)調(diào)用onTick方法
   */
  public TimeCount(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
  }
  @Override
  public void onTick(long millisUntilFinished) {   //倒計(jì)時(shí)狀態(tài)
    getVerificationCodeBtn.setClickable(false);     //設(shè)置button此時(shí)不可點(diǎn)擊
    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的倒計(jì)時(shí)文字
  }
  @Override
  public void onFinish() {      //倒計(jì)時(shí)結(jié)束狀態(tài)
    getVerificationCodeBtn.setBackground(getResources().getDrawable(R.drawable.login_btn_bg));
    getVerificationCodeBtn.setTextColor(getResources().getColor(R.color.white));
    getVerificationCodeBtn.setClickable(true);   //重新設(shè)置button為可點(diǎn)擊
    getVerificationCodeBtn.setText("重新獲取");   //修改button的文字
  }
}

最后在代碼中,聲明TimeCount并實(shí)例化,在button的點(diǎn)擊事件中調(diào)用.start()方法啟動(dòng)定時(shí)器。

  TimeCount timeCount = new TimeCount(60000,1000);
  timeCount.start();

總結(jié)

以上所述是小編給大家介紹的android實(shí)現(xiàn)一個(gè)圖片驗(yàn)證碼倒計(jì)時(shí)功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論