安卓:TextInputLayout 组件始终显示错误图标

19
我注意到自从几天前开始,我所有的TextInputLayouts都一直启用“错误感叹号”。我很久以前就没有改变任何有关那些TextInputLayouts的东西,所以我真的不明白发生了什么事情。
这是它的外观截图: 你有什么想法是这个问题的根源吗?最近有什么关于TextInputLayouts的更新吗?
非常感谢您的帮助。
编辑: 这是相关代码: .xml文件非常简单。像这样列出了许多TextInputLayouts和EditTexts:
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/default_margin"
    android:layout_marginTop="@dimen/default_margin"
    android:layout_marginRight="@dimen/default_margin">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/txtAddressTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/PROFILE_SCREEN_ADDRESS_INPUT_TITLE"
        android:inputType="textPersonName|textCapWords" />

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

此外,在我的 Kotlin 代码中完全没有提到 setError()。


1
TextInputLayout的错误提示是在EditText下方的一个TextView。这看起来像是直接在EditText上调用了setError(),而不是在TextInputLayout上调用。 - Mike M.
在 Kotlin 中,它只是 editText.error = ... - Mike M.
@MikeM。我不使用“editText.error”。 此外,红色感叹号出现在.xml预览中。好像是默认启用的 O_o - Valentin
所以,这是一个工具问题吗?安装后在您的设备上没有发生? - denvercoder9
1
请提供一个 [mcve]。 - Mike M.
显示剩余3条评论
2个回答

53

你可以尝试这样做。但它将永久地移除错误图标。如果你想再次显示它,你需要以编程方式进行操作。

app:errorIconDrawable="@null"

注意。此属性必须设置在布局上,而不是编辑文本本身。 - Marco7757

6

编辑: 看起来使用com.google.android.material:material:1.2.0-alpha04已经修复了问题。


嗨,我发现了问题。实际上,我将Material库的版本从com.google.android.material:material:1.1.0-alpha08更新到com.google.android.material:material:1.1.0-alpha09

谷歌改变了文本字段的行为(请参见此处:https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha09):

文本字段:

  • 添加选项以使TextInputLayout图标不可选择(6a88f2b)
  • 为文本字段实现错误图标(3f73804)

你成功解决了这个问题吗?而且没有降级到1.1.0-alpha08版本吗?如果是这样,你做了哪些更改? - davidk
我正在使用 implementation 'com.google.android.material:material:1.1.0-alpha10',但仍然遇到这个问题。 - OhhhThatVarun

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接