国产探花免费观看_亚洲丰满少妇自慰呻吟_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實現一個圖片驗證碼倒計時功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保靖县| 文安县| 桦川县| 元阳县| 台安县| 天台县| 永善县| 新巴尔虎右旗| 桂阳县| 县级市| 华坪县| 苍梧县| 罗江县| 高邮市| 嵩明县| 当雄县| 鸡西市| 罗定市| 大同市| 远安县| 永福县| 澎湖县| 曲阳县| 柳林县| 镇江市| 延吉市| 新泰市| 石嘴山市| 大同县| 嘉黎县| 东乡县| 乌拉特后旗| 贵溪市| 阿尔山市| 赣榆县| 曲松县| 新巴尔虎右旗| 开远市| 三江| 金寨县| 连平县|