如何解决更改textInputLayout的笔触颜色
发生错误时(例如,当用户输入无效的名称(插入符号,例如:@ $等)时),我想使textBox的笔触颜色为红色,我该怎么做,这是我的文本框代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/etFullNameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:textColorHint="#b4ffff"
app:startIconTint="#b4ffff"
android:layout_margin="20dp"
app:startIconDrawable="@drawable/ic_person"
app:boxStrokeErrorColor="@color/color_on_secondary"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etFullName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
解决方法
带有错误的默认笔触颜色是红色。
您可以在任何情况下使用 boxStrokeErrorColor
属性对其进行自定义:
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeErrorColor="@color/..."
...>
然后,您必须提供自定义验证。像这样:
etFullName.addTextChangedListener(
afterTextChanged = {
if (!isValid(it)){
etFullNameLayout.error = "Error!"
}
}
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。