CountDownTimer倒计时
16lz
2021-01-23
倒计时原来都用handler+timer写,现在发现Android 已将封装好了一个类CountDownTimer
public CountDownTimer startCount(Button button, int time) { //由于CountDownTimer有一定的延迟,所以这里设置3400 CountDownTimer countDownTimer = new CountDownTimer(time + 400, 1000) { @Override public void onTick(long millisUntilFinished) { button.setText("跳过(" + millisUntilFinished / 1000 + "s)"); } @Override public void onFinish() { button.setText("跳过(" + 0 + "s)"); SplashPresenter.this.mvpView.countEnd(); } }.start(); return countDownTimer; }
cancle在onTick()中是不起作用的,所以可以在外面进行取消
更多相关文章
- 今天发现了一个不错的android加载动画
- Android performance今天的发现
- [Android应用开发]添加了两个Button后发现只显示一个
- Kotlin 风险高、RxJava 已过时,Android 原生开发现状分析!
- 归纳整理一些工作学习中发现的不错的网站、博客地址等
- 发现自己喜欢了移动端开发--Android
- 今天发现的一些优秀的资源网站
- Android 出错显示找不到id,但你发现id是存在的