如果 2 编辑文本是填充使用,如何启用按钮'androidx.core:core-ktx:1.1.0'
?
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
editTextEmailOrPhone.doOnTextChanged { emailOrPhone, _, _, _ ->
if (isValidEmailOrPhone(emailOrPhone.toString())) {
buttonLogin.isEnabled = true
} else {
edtPassword.doOnTextChanged { password, _, _, _ ->
buttonLogin.isEnabled = password.toString().length >= 8
}
}
}
}
private fun isValidEmailOrPhone(text: String): Boolean =
android.util.Patterns.EMAIL_ADDRESS.matcher(text).matches() || android.util.Patterns.PHONE.matcher(
text
).matches()
我试过了。如果我填写电子邮件(启用按钮)<== 看起来不错
但是,如果我删除电子邮件(按钮未禁用)<== 问题