直播短视频源码Android开发,实现发送手机号验证码倒计时
直播短视频源码Android开发,实现发送手机号验证码倒计时
获取验证码倒计时通过TimeCount 计时器实现的,记得在倒计时过程中将按钮设置为禁用
<LinearLayout android:layout_marginTop="@dimen/dp_100" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dp_20" android:paddingTop="@dimen/dp_50" android:layout_marginRight="@dimen/dp_20" android:paddingBottom="@dimen/dp_50" android:background="@color/white" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/dp_35" android:layout_marginLeft="@dimen/dp_5" android:layout_marginRight="@dimen/dp_5" android:background="@drawable/bk_register" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/dp_24" android:layout_height="@dimen/dp_24" android:layout_gravity="center" android:layout_marginLeft="@dimen/dp_10" android:src="@drawable/ic_phone_iphone" /> <EditText android:id="@+id/et_phone" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="@dimen/dp_6" android:background="@null" android:textSize="@dimen/sp_16" android:hint="请输入手机号码" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/dp_35" android:layout_marginLeft="@dimen/dp_5" android:layout_marginTop="@dimen/dp_10" android:layout_marginRight="@dimen/dp_5" android:background="@drawable/bk_register"> <ImageView android:layout_width="@dimen/dp_24" android:layout_height="@dimen/dp_24" android:layout_centerVertical="true" android:layout_marginLeft="@dimen/dp_10" android:src="@drawable/ic_lock_black" /> <EditText android:textSize="@dimen/sp_16" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="@dimen/dp_40" android:background="@null" android:hint="请输入验证码" /> <TextView android:id="@+id/tv_yzm" android:textSize="@dimen/sp_16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="@dimen/dp_10" android:textColor="#0a71b0" android:text="获取验证码" /> </RelativeLayout> <Button android:layout_width="match_parent" android:layout_height="@dimen/dp_35" android:layout_marginLeft="@dimen/dp_5" android:layout_marginTop="@dimen/dp_10" android:layout_marginRight="@dimen/dp_5" android:background="@drawable/bg_setting_button" android:text="确认" android:textColor="@color/white" android:textSize="@dimen/sp_14" /> </LinearLayout>
.java文件
private TextView tvYzm; private EditText etPhone; private TimeCount time; ... onCrate(Bundle savedInstanceState){ ... time = new TimeCount(60000, 1000); tvYzm = findViewById(R.id.tv_yzm); etPhone = findViewById(R.id.et_phone); tvYzm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (TextUtils.isEmpty(etPhone.getText().toString())) { etPhone.setError("请先输入手机号"); return; } if (!isMobileNO(etPhone.getText().toString())) { etPhone.setError("手机号格式不正确"); return; } time.start();//成功按钮发送验证码倒计时 } });}
工具
//验证码倒计时 class TimeCount extends CountDownTimer { public TimeCount(long millisinfuture, long countdowninterval) { super(millisinfuture, countdowninterval); } @Override public void onTick(long l) { tvYzm.setClickable(false); tvYzm.setText("(" + l / 1000 + ")s"); tvYzm.setTextColor(getResources().getColor(R.color.gray)); } @Override public void onFinish() { tvYzm.setText("发送验证码"); tvYzm.setClickable(true); } } //判断手机号码格式是否正确 private boolean isMobileNO(String mobiles) { String telRegex = "^((1[3,5,7,8][0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"; if (TextUtils.isEmpty(mobiles)) { return false; } else { return mobiles.matches(telRegex); } } 以上就
是 直播短视频源码Android开发,实现发送手机号验证码倒计时,更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现