带货直播源码,实现验证码倒计时按钮相关的代码
private var mDisposable: Disposable? = null
/**
* 验证码按钮倒计时
*/
private fun countDown(){
val countDownStr = resources.getString(R.string.get_sms_code_count_down)
setCodeButtonEnable(false)
val flowable: Flowable<Long> = Flowable.intervalRange(1,60,0,1,TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext {
bt_code.text = countDownStr.format(60-it)
}
.doOnComplete {
setCodeButtonEnable(true)
}
mDisposable = flowable.subscribe()
}
override fun onDestroy() {
super.onDestroy()
mDisposable?.let {
it.dispose()
}
}
private fun setCodeButtonEnable(enable: Boolean){
bt_code.isEnabled = enable
bt_code.setBackgroundColor(if (enable) ContextCompat.getColor(this,R.color.colorBlue) else ContextCompat.getColor(this,R.color.colorGray7E))
if (enable) bt_code.text = resources.getString(R.string.get_sms_code)
}
以上就是 带货直播源码,实现验证码倒计时按钮相关的代码,更多内容欢迎关注之后的文章