【发布时间】:2020-04-01 14:10:50
【问题描述】:
所以我做了一些验证的密码,我做的第一件事是在 passittord 编辑文本上进行验证,当我输入密码时,会出现一个红色的关闭图标并显示一条消息错误,密码填写后关闭图标还是没有变成绿色的勾号图标,当密码里有字母、大写字母和数字时,关闭的图标变成了成功或核对表图标,有没有朋友能帮我解决这个问题?
我做了这个仍然显示关闭图标
这是代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputPassword"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:hint="Password"
app:counterEnabled="true"
app:counterMaxLength="6"
app:endIconMode="clear_text"
app:endIconDrawable="@drawable/ic_canceles"
app:errorEnabled="true"
app:endIconTint="#DF0000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputEmail">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:maxLines="1"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
这是代码 kotlin
submitButtom.setOnClickListener {
if (editTextPassword.text.toString().length < 6) {
editTextPassword.setError("password minimum contain 6 character")
editTextPassword.requestFocus()
editTextPassword.isEnabled = true
}
if (editTextPassword.text.toString().length > 6) {
editTextPassword.setError("password maximum contain 6 character")
editTextPassword.requestFocus()
}
if (editTextPassword.text.toString().equals("")) {
editTextPassword.setError("please enter password")
editTextPassword.requestFocus();
}
}
【问题讨论】:
-
这是您应该查看的an example。如果链接可能断开,我向未来的人道歉,但这是一个广泛的话题。我建议 OP 还检查各个站点以了解不同的设置方式。
-
使用Reg-Ex 进行密码验证。
-
感谢您帮助我获得参考@ADM