TextInputLayout 中的 ErrorIconDrawable 不显示任何内容

ErrorIconDrawable in TextInputLayout does not show anything

我正在尝试在 textInputLayout 错误中设置图标,如下所示:

我在 TextInputLayout 中设置了这个 app:errorIconDrawable="@drawable/login_erroricon" 但是当我 运行 应用程序时它没有显示任何东西。

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout_login_email"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="32dp"
    app:hintEnabled="false"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView_login_emailLabel"
    app:startIconDrawable="@drawable/email_icon"
    app:startIconTint="@color/white"
    app:errorIconDrawable="@drawable/login_erroricon">

我也在代码中尝试过,但它没有出现任何东西:

 textInputLayout_login_email.errorIconDrawable=resources.getDrawable(R.drawable.login_erroricon)

注意:文字没问题,但图标不见了。

正如 material.io 文档所述,TextInputLayout 包含:

  1. 容器
  2. 前导图标
  3. 标签
  4. 输入文字
  5. 尾随图标
  6. 激活指标
  7. Helper/error/counter 文字
  8. Prefix/suffix/placeholder(未显示)

Helper/Error/Counter 文本没有图标,它只存在于容器的右侧 (5)

您想要实现的可以是自定义实现。

在您的 TextInputLayout 下添加一个带有 drawableStart 属性的 TextView。