Android中获取验证码时的倒计时效果
来源:互联网 发布:购买软件合同 印花税 编辑:程序博客网 时间:2024/06/04 17:46
项目结构:
核心代码:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/text_fragment_login_logo"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="32dp"
android:scaleType="centerInside"
android:textSize="28sp"
android:textColor="#fff"
android:gravity="center"
android:textStyle="bold"
android:text="停车宝(代泊员)"/>
<EditText
android:id="@+id/login_ed_shoujihao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:hint="手机号"
android:maxLength="11"
android:maxLines="1"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:numeric="integer" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/login_ed_yanzhengma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="验证码"
android:maxLength="6"
android:maxLines="1"
android:layout_marginRight="8dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"/>
<Button
android:id="@+id/login_btn_huoquyanzhengma"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="login_btn_huoquyanzhengma_onclick"
android:textColor="#fff"
android:textSize="20sp"
android:text="获取验证码" />
</LinearLayout>
<Button
android:id="@+id/login_btn_denglu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#e65400"
android:onClick="login_denglu_onclick"
android:text="登录"
android:padding="15dp"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
MainActivity
public class MainActivity extends Activity implements OnClickListener{
Thread thread=null;
private boolean tag = true;
private int i = 60;
public boolean isChange = false;
private Button btnCode=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnCode = (Button) findViewById(R.id.login_btn_huoquyanzhengma);
btnCode.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.login_btn_huoquyanzhengma) {
btnCode.setText("获取验证码");
btnCode.setClickable(true);
isChange = true;
changeBtnGetCode();
}
}
private void changeBtnGetCode() {
thread = new Thread() {
@Override
public void run() {
if (tag) {
while (i > 0) {
i--;
if (MainActivity.this== null) {
break;
}
//当文本框内容改变时,结束循环。
// if (isChange && !btnCode.isClickable()) {
// isChange = false;
// break;
// }
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
btnCode.setText("获取验证码(" + i + ")");
btnCode.setClickable(false);
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
tag = false;
}
i = 60;
tag = true;
if (MainActivity.this != null) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
btnCode.setText("获取验证码");
btnCode.setClickable(true);
}
});
}
};
};
thread.start();
}
}//class
没有明白下载我的例子:
http://download.csdn.net/detail/zhaihaohao1/8387081
- Android中获取验证码时的倒计时效果
- Android中获取验证码时的倒计时效果
- Android中获取验证码时的倒计时效果
- Android获取验证码倒计时效果
- Android中获取验证码时的倒计时操作
- 手机获取验证码的倒计时效果
- android中获取手机验证码的倒计时操作
- Android 点击Button获取验证码倒计时效果
- Android获取验证码时的倒计时 CountDownTimer使用
- 一段实现获取验证码倒计时效果的Jquery
- Android获取验证码倒计时
- Android 获取验证码倒计时
- Android获取验证码倒计时
- android 获取验证码倒计时
- 获取短信验证码倒计时效果
- js获取验证码倒计时效果
- 倒计时(获取验证码的倒计时)
- Android实现发送验证码倒计时的效果
- 蓝牙编程介绍
- 算法学习-动态规划(最长公共子序列)
- Visual Studio添加整个目录到空项目中
- android studio如何使用git
- Unity4.6的Crack
- Android中获取验证码时的倒计时效果
- iSCSI存储设备的udev绑定
- fiddler无法抓取chrome解决方法
- Linux kernel探究IO Scheduling
- Unity3D设置纹理格式
- 第16题:爬楼梯
- GStreamer开发介绍
- 分布式缓存系统Memcached(八)——主线程之main函数
- Go语言源码中的Rabin-Karp算法