视频聊天app源码,Android 发送验证码倒计时
视频聊天app源码,Android 发送验证码倒计时实现的相关代码
一、视频聊天app源码使用ValueAnimator实现了倒计时的动画效果
```handlebars <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:id="@+id/huo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="获取验证码" android:textSize="20sp" android:textStyle="bold" android:textColor="#00BCD4" android:layout_gravity="center" android:layout_margin="30dp" > </TextView> </LinearLayout> ```
二、当视频聊天app源码点击的时候有一个小bug,当它倒计时的时候我在点击又从新开始倒计时,这时设置了一个boolean 值,当为true的时候让它执行倒计时给它设置成false,再次点击就不会从新开始执行直到60秒结束,显示重新发送的时候可以从新执行。
```handlebars package com.wd.wangzhuangyu; import androidx.appcompat.app.AppCompatActivity; import android.animation.ValueAnimator; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private TextView huo; boolean a = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取id控件 huo = findViewById(R.id.huo); //设置点击事件 huo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (a){ ValueAnimator animator = ValueAnimator.ofInt(60,0); //设置时间 animator.setDuration(60000); //均匀显示 animator.setInterpolator(new LinearInterpolator()); //监听 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (Integer) animation.getAnimatedValue(); huo.setText(value+"s重新发送"); huo.setTextColor(Color.GRAY); if(value==0){ huo.setText("重新发送"); huo.setTextColor(Color.BLUE); a = true; } } }); //开启线程 animator.start(); a=false; }else { Toast.makeText(MainActivity.this, "稍后重试", Toast.LENGTH_SHORT).show(); } } }); } } ```
以上就是 视频聊天app源码,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岁的心里话
· 按钮权限的设计及实现