【问题标题】:how to change the default background color of EidtText error message如何更改 EditText 错误消息的默认背景颜色
【发布时间】:2016-06-17 06:45:32
【问题描述】:

我想将错误消息的背景颜色更改为白色,将文本颜色更改为红色。 我可以使用 html 格式的文本更改文本颜色。由于它不支持 css 样式,我无法更改错误消息的背景颜色。

【问题讨论】:

  • 你应该添加你正在使用的代码。

标签: android validation android-edittext message


【解决方案1】:

我认为您不能使用默认弹出窗口更改背景,您必须创建自己的弹出窗口。

但更好的解决方案可能是使用 TextInputLayout 包装您的 EditText,然后在 TextInputLayout 上设置错误。

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Hint"/>

</android.support.design.widget.TextInputLayout>

然后使用

mTextInputLayout.setError("your error string");

【讨论】:

    猜你喜欢
    • 2015-09-19
    • 2022-01-15
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    相关资源
    最近更新 更多