zoukankan      html  css  js  c++  java
  • Android中注册获取验证码倒计时按钮

    1. public class CountDownTimerUtils extends CountDownTimer {  
    2.     private TextView mTextView;  
    3.   
    4.     /** 
    5.      * @param textView          The TextView 
    6.      * 
    7.      * 
    8.      * @param millisInFuture    The number of millis in the future from the call 
    9.      *                          to {@link #start()} until the countdown is done and {@link #onFinish()} 
    10.      *                          is called. 
    11.      * @param countDownInterval The interval along the way to receiver 
    12.      *                          {@link #onTick(long)} callbacks. 
    13.      */  
    14.     public CountDownTimerUtils(TextView textView, long millisInFuture, long countDownInterval) {  
    15.         super(millisInFuture, countDownInterval);  
    16.         this.mTextView = textView;  
    17.     }  
    18.   
    19.     @Override  
    20.     public void onTick(long millisUntilFinished) {  
    21.         mTextView.setClickable(false); //设置不可点击  
    22.         mTextView.setText(millisUntilFinished / 1000 + "秒后可重新发送");  //设置倒计时时间  
    23.         mTextView.setBackgroundResource(R.drawable.bg_identify_code_press); //设置按钮为灰色,这时是不能点击的  
    24.   
    25.         /** 
    26.          * 超链接 URLSpan 
    27.          * 文字背景颜色 BackgroundColorSpan 
    28.          * 文字颜色 ForegroundColorSpan 
    29.          * 字体大小 AbsoluteSizeSpan 
    30.          * 粗体、斜体 StyleSpan 
    31.          * 删除线 StrikethroughSpan 
    32.          * 下划线 UnderlineSpan 
    33.          * 图片 ImageSpan 
    34.          * http://blog.csdn.net/ah200614435/article/details/7914459 
    35.          */  
    36.         SpannableString spannableString = new SpannableString(mTextView.getText().toString());  //获取按钮上的文字  
    37.         ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);  
    38.         /** 
    39.          * public void setSpan(Object what, int start, int end, int flags) { 
    40.          * 主要是start跟end,start是起始位置,无论中英文,都算一个。 
    41.          * 从0开始计算起。end是结束位置,所以处理的文字,包含开始位置,但不包含结束位置。 
    42.          */  
    43.         spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//将倒计时的时间设置为红色  
    44.         mTextView.setText(spannableString);  
    45.     }  
    46.   
    47.     @Override  
    48.     public void onFinish() {  
    49.         mTextView.setText("重新获取验证码");  
    50.         mTextView.setClickable(true);//重新获得点击  
    51.         mTextView.setBackgroundResource(R.drawable.bg_identify_code_normal);  //还原背景色  
    52.     }  

    使用:

    CountDownTimerUtils mCountDownTimerUtils = new CountDownTimerUtils(mButton, 60000, 1000);

    mCountDownTimerUtils.start();



  • 相关阅读:
    张季跃 201771010139《面向对象程序设计(java)》第十五周学习总结
    张季跃 201771010139《面向对象程序设计(java)》第十四周学习总结
    张季跃 201771010139《面向对象程序设计(java)》第十三周学习总结
    201771010142-张燕 实验四 软件项目案例分析—项目报告
    201771010142-张燕 实验三 结对项目—《西北师范大学疫情防控信息系统》项目报告
    201771010142-张燕 实验二 个人项目—<学生疫情上报系统>
    201771010142-张燕 实验一 软件工程准备—<软件工程的初步了解和学习目标>
    实验十八 总复习
    实验十七 线程同步控制
    实验十六 线程技术
  • 原文地址:https://www.cnblogs.com/kim-liu/p/7754490.html
Copyright © 2011-2022 走看看