android 获取验证码的 按钮

来源:互联网 发布:天猫商城淘宝店 编辑:程序博客网 时间:2024/06/05 08:58
public class TimeCountUtil extends CountDownTimer {    private Activity mActivity;private Button btn;//按钮// 在这个构造方法里需要传入三个参数,一个是Activity,一个是总的时间millisInFuture,一个是countDownInterval,然后就是你在哪个按钮上做这个是,就把这个按钮传过来就可以了public TimeCountUtil( Activity mActivity,long millisInFuture, long countDownInterval,Button btn) {super(millisInFuture, countDownInterval);this.mActivity = mActivity;this.btn =btn;}@SuppressLint("NewApi")@Overridepublic void onTick(long millisUntilFinished) {btn.setClickable(false);//设置不能点击btn.setText(millisUntilFinished / 1000 + "秒后可重新发送");//设置倒计时时间 //设置按钮为灰色,这时是不能点击的btn.setBackground(mActivity.getResources().getDrawable(R.drawable.bg_duck_back));Spannable span = new SpannableString(btn.getText().toString());//获取按钮的文字span.setSpan(new ForegroundColorSpan(Color.RED), 0, 2,                              Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//讲倒计时时间显示为红色btn.setText(span);}@SuppressLint("NewApi")@Overridepublic void onFinish() {btn.setText("重新获取验证码");btn.setClickable(true);//重新获得点击btn.setBackground(mActivity.getResources().getDrawable(R.drawable.bg_btn_back));//还原背景色}}

0 0
原创粉丝点击