CountDownTimer倒计时器,获取验证码,的使用
来源:互联网 发布:数据展现工具 编辑:程序博客网 时间:2024/06/05 09:17
首先 先把封装好的timercount贴出来
public class TimerCount extends CountDownTimer {
private TextView bnt;
private OnStop onStop;
public TimerCount(long millisInFuture, long countDownInterval, TextView bnt) {
super(millisInFuture, countDownInterval);
this.bnt = bnt;
}
public TimerCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
bnt.setClickable(true);
// bnt.setBackgroundResource(R.drawable.bt_bg);//设置为正常色
bnt.setText("获取验证码");
if (onStop != null) {
onStop.onStop(false);
}
}
@Override
public void onTick(long arg0) {
// TODO Auto-generated method stub
bnt.setClickable(false);
// bnt.setBackgroundResource(R.drawable.shape_forgetpwd_bg);//设置为灰�?
bnt.setText(arg0 / 1000 + "S后重发送");
// bnt.setText("还剩"+arg0 / 1000 + "�?");
if (onStop != null) {
onStop.onStop(true);
}
}
public void onTimerStop(OnStop onStop){
this.onStop = onStop;
}
public interface OnStop{
void onStop(boolean flag);
}
}
然后 在mianactivity中写相关代码
private TimerCount timerCount;
private TextView actRgSendCard;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actRgSendCard = (TextView)findViewById(R.id.actRgSendCard);
actRgSendCard.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
getCode();
}
});
}
//获取验证码
private void getCode(){
timerCount = new TimerCount(60000, 1000, actRgSendCard);
timerCount.start();
}
}
xml布局文件
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.timercount.MainActivity" >
<RelativeLayout
android:id="@+id/iphone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_phone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="手机号"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="@+id/find_iphone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tv_phone"
android:background="@null"
android:gravity="center_vertical"
android:hint="请输入手机号"
android:inputType="number"
android:singleLine="true"
android:textColor="#444444"
android:textColorHint="#cccccc"
android:textCursorDrawable="@null"
android:textSize="16sp" />
<View
android:id="@+id/iphone_line"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/auth_code"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_phone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="验证码"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/tv_phone"
android:gravity="center_vertical"
android:orientation="horizontal" >
<EditText
android:id="@+id/find_authcode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="@null"
android:gravity="center_vertical"
android:hint="请输入验证码"
android:inputType="number"
android:singleLine="true"
android:textColor="#444444"
android:textColorHint="#cccccc"
android:textCursorDrawable="@null"
android:textSize="16sp" />
<TextView
android:id="@+id/actRgSendCard"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="获取验证码"
android:textColor="#028ae6"
android:textSize="16sp" />
</LinearLayout>
<View
android:id="@+id/iphone_line"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="#000000" />
</RelativeLayout>
</LinearLayout>
- CountDownTimer倒计时器,获取验证码,的使用
- CountDownTimer倒计时器的使用
- CountDownTimer 倒计时器的使用
- CountDownTimer倒计时器的使用
- CountDownTimer短信验证码倒计时器
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- Android CountDownTimer倒计时器的使用
- JavaScript推荐资料合集(前端必看)
- 小雷的冰茶几(并查集)
- iOS协议实现多继承
- 原码反码补码
- 银行软件测试面试问题
- CountDownTimer倒计时器,获取验证码,的使用
- 编译Android内核
- 面试感悟:3年工作经验程序员应有的技能
- STM32 USB 复合设备开发的技巧
- JVM运行时数据区域解析
- 进程与线程的区别
- JDK、tomcat环境变量的配置
- Android中Dialog(对话框)的用法
- Java:Annotation(注解)--原理到案例