Commit 92c2e619 authored by 宋永孟's avatar 宋永孟

add 给login页面添加倒计时

parent 4b9b8831
...@@ -4,6 +4,7 @@ import android.os.Bundle ...@@ -4,6 +4,7 @@ import android.os.Bundle
import com.yidian.common.XRouterPathConstants.Companion.LOGIN_LIFE_CIRCLE import com.yidian.common.XRouterPathConstants.Companion.LOGIN_LIFE_CIRCLE
import com.yidian.common.base.BaseActivity import com.yidian.common.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.databinding.ActivityLoginBinding import com.yidian.shenghuoquan.newscontent.databinding.ActivityLoginBinding
import com.yidian.shenghuoquan.newscontent.utils.CountDownTimerUtils
/** /**
* Author: sym * Author: sym
...@@ -11,6 +12,8 @@ import com.yidian.shenghuoquan.newscontent.databinding.ActivityLoginBinding ...@@ -11,6 +12,8 @@ import com.yidian.shenghuoquan.newscontent.databinding.ActivityLoginBinding
* Describe: * Describe:
*/ */
class LoginLifeCircleActivity : BaseActivity<ActivityLoginBinding>() { class LoginLifeCircleActivity : BaseActivity<ActivityLoginBinding>() {
private lateinit var mCountDownTimerUtils: CountDownTimerUtils
override fun createViewBinding(): ActivityLoginBinding { override fun createViewBinding(): ActivityLoginBinding {
return ActivityLoginBinding.inflate(layoutInflater) return ActivityLoginBinding.inflate(layoutInflater)
} }
...@@ -21,6 +24,17 @@ class LoginLifeCircleActivity : BaseActivity<ActivityLoginBinding>() { ...@@ -21,6 +24,17 @@ class LoginLifeCircleActivity : BaseActivity<ActivityLoginBinding>() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
initView()
setOnListener()
}
private fun initView() {
mCountDownTimerUtils = CountDownTimerUtils(viewBind.getBtn, 6000, 1000)
}
private fun setOnListener() {
viewBind.getBtn.setOnClickListener {
mCountDownTimerUtils.start()
}
} }
} }
\ No newline at end of file
package com.yidian.shenghuoquan.newscontent.utils
import android.os.CountDownTimer
import android.widget.TextView
/**
* Author: sym
* Date: 2021/5/18 7:43 PM
* Describe:
*/
class CountDownTimerUtils : CountDownTimer {
private var mTextView: TextView? = null
constructor(textView: TextView, millisInFuture: Long, countDownInterval: Long) : super(millisInFuture, countDownInterval) {
mTextView = textView
}
override fun onTick(millisUntilFinished: Long) {
mTextView!!.isClickable = false //设置不可点击
var temp: Long = millisUntilFinished / 1000
mTextView!!.text = temp.toString() + "秒后可重新发送"//设置倒计时时间
}
override fun onFinish() {
mTextView!!.text = "重新获取验证码"
mTextView!!.isClickable = true //重新获得点击
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<EditText
android:id="@+id/phone_number_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="141dp"
android:layout_marginStart="40dp"
android:ems="10"
android:hint="请输入手机号">
<requestFocus />
</EditText>
<EditText
android:id="@+id/number_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/phone_number_edit"
android:layout_marginTop="26dp"
android:layout_marginStart="40dp"
android:ems="10"
android:hint="请输入验证码" />
<TextView <TextView
android:layout_width="match_parent" android:id="@+id/get_btn"
android:layout_height="match_parent" android:layout_width="wrap_content"
android:gravity="center" android:layout_height="wrap_content"
android:text="login"/> android:layout_alignBottom="@+id/number_edit"
android:layout_alignParentRight="true"
android:text="获取验证码" />
<Button
android:id="@+id/login_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="登陆" />
</LinearLayout> </RelativeLayout>
\ No newline at end of file \ No newline at end of file
...@@ -7,7 +7,6 @@ buildscript { ...@@ -7,7 +7,6 @@ buildscript {
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url "http://download.flutter.io" }
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
maven { url "https://dl.bintray.com/thelasterstar/maven/" } maven { url "https://dl.bintray.com/thelasterstar/maven/" }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment