如何更改Edittext错误框的背景颜色

问题描述 投票:0回答:2

我无法更改错误文本框颜色的背景颜色。

想要更改错误框的背景颜色而不是文本颜色。我尝试设置 setErrorTextColor、setErrorColor、setBackGroundColor 的方式未定义。请提出一些解决方案。 预先感谢。

android xml android-studio android-edittext
2个回答
0
投票

您可以使用以下代码更改editText错误块的颜色。

yourEditText.setErrorColor(Color.parseColor("Pass Your Color Code"));

0
投票

我建议您切换到Material.io TextInputLayout,它不仅提供更流畅的错误处理API,而且还具有更多自定义功能

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label">

<com.google.android.material.textfield.TextInputEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

</com.google.android.material.textfield.TextInputLayout>

有关 Material.io 版本的 Edittext 附带的所有功能的深入文档,请访问 Material.io 文本字段 - Android

© www.soinside.com 2019 - 2024. All rights reserved.