zoukankan      html  css  js  c++  java
  • 短信验证码的使用

    复制代码
     Button getVerCodeButton = (Button) findViewById(R.id.login_get_ver_code);
     private class VerCodeTimer extends CountDownTimer {
    
            private int seconds;
            private int interval;
            private int nowTime;
    
            //millisInFuture为你设置的此次倒计时的总时长,比如60秒就设置为60000
            //countDownInterval为你设置的时间间隔,比如一般为1秒,根据需要自定义。
            public VerCodeTimer(long millisInFuture, long countDownInterval) {
    
                super(millisInFuture, countDownInterval);
                seconds = (int) (millisInFuture / 1000);
                interval= (int) (countDownInterval/1000);
                nowTime=seconds;
            }
    
            //每过你规定的时间间隔做的操作
            @Override
            public void onTick(long millisUntilFinished) {
                nowTime-=interval;
                getVerCodeButton.setText(nowTime + "秒后重新获取");
            }
    
            //倒计时结束时做的操作↓↓
            @Override
            public void onFinish() {
                getVerCodeButton.setTextSize(10);
                getVerCodeButton.setText("重新获取验证码");
                getVerCodeButton.setClickable(true);
                getVerCodeButton.setBackgroundResource(R.drawable.login_get_ver_code_before_bg);
            }
        }
    复制代码

    使用的时候:

     getVerCodeButton.setTextSize(11);
     getVerCodeButton.setClickable(false);
     getVerCodeButton.setBackgroundResource(R.drawable.login_get_ver_code_ago_bg);
     mVerCodeTimer = new VerCodeTimer(10000, 1000);
     mVerCodeTimer.start();

    login_edit_normal_bg.xml:

    复制代码
    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        android:useLevel="false">
    
        <!-- 背景填充颜色值 -->
        <solid android:color="#6c948b" />
    
        <!-- radius值越大,越趋于圆形 -->
        <corners android:radius="10dip" />
    
        <!-- 圆角图像内部填充四周的大小 ,将会以此挤压内部布置的view -->
        <padding
            android:bottom="10dip"
            android:left="10dip"
            android:right="10dip"
            android:top="10dip" />
    
    </shape>
    复制代码

    login_edit_passed_bg.xml:

    复制代码
    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        android:useLevel="false">
    
        <!-- 背景填充颜色值 -->
        <solid android:color="#509989" />
    
        <!-- radius值越大,越趋于圆形 -->
        <corners android:radius="10dip" />
    
        <!-- 圆角图像内部填充四周的大小 ,将会以此挤压内部布置的view -->
        <padding
            android:bottom="10dip"
            android:left="10dip"
            android:right="10dip"
            android:top="10dip" />
    
    </shape>
  • 相关阅读:
    java pojo类
    web(一)
    java通过配置文件(Properties类)连接Oracle数据库代码示例
    java数组排序(插入排序、冒泡排序、选择排序)与递归 代码示例
    匿名内部类
    java反射机制
    ubuntu安装kvm流程
    squid代理服务问答
    ftp nfs samba比较
    Samba服务问答
  • 原文地址:https://www.cnblogs.com/neo-java/p/6840779.html
Copyright © 2011-2022 走看看