国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android實現一個圖片驗證碼倒計時功能

2019-12-12 01:44:24
字體:
來源:轉載
供稿:網友

1.如圖所示,要實現一個驗證碼的倒計時的效果      

                       

2.實現

  圖中獲取驗證碼那塊是一個button按鈕

  關鍵部分,聲明一個TimeCount,繼承自CountDownTimer

/*驗證碼倒計時*/private class TimeCount extends CountDownTimer{  /**   * @param millisInFuture  總時間長度(毫秒)   * @param countDownInterval 時間間隔(毫秒),每經過一次時間間隔都會調用onTick方法   */  public TimeCount(long millisInFuture, long countDownInterval) {    super(millisInFuture, countDownInterval);  }  @Override  public void onTick(long millisUntilFinished) {   //倒計時狀態    getVerificationCodeBtn.setClickable(false);     //設置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后可重新發送");//顯示button的倒計時文字  }  @Override  public void onFinish() {      //倒計時結束狀態    getVerificationCodeBtn.setBackground(getResources().getDrawable(R.drawable.login_btn_bg));    getVerificationCodeBtn.setTextColor(getResources().getColor(R.color.white));    getVerificationCodeBtn.setClickable(true);   //重新設置button為可點擊    getVerificationCodeBtn.setText("重新獲取");   //修改button的文字  }}

最后在代碼中,聲明TimeCount并實例化,在button的點擊事件中調用.start()方法啟動定時器。

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

總結

以上所述是小編給大家介紹的android實現一個圖片驗證碼倒計時功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黑水县| 富川| 神池县| 延长县| 丰台区| 图木舒克市| 林甸县| 丹寨县| 泉州市| 东宁县| 驻马店市| 江川县| 南丹县| 防城港市| 杨浦区| 德州市| 德清县| 镇安县| 汶上县| 望都县| 仙居县| 当阳市| 宣化县| 河西区| 绥化市| 睢宁县| 芦溪县| 娄烦县| 吴桥县| 定襄县| 伊吾县| 黄陵县| 琼海市| 兴隆县| 孝感市| 常德市| 丹凤县| 重庆市| 松潘县| 莒南县| 修水县|