TextInputLayout 中的 ErrorIconDrawable 没有显示任何内容。

4
我试图在 textInputLayout 的错误提示中设置一个图标,方法如下:

enter image description here

我在 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)

注意:文本正常,但图标消失了。


1
错误图标在右侧。请查看文档 - Gabriele Mariotti
1个回答

3
作为material.io文档所述,TextInputLayout包含以下内容:

enter image description here

  1. 容器
  2. 前导图标
  3. 标签
  4. 输入文本
  5. 尾随图标
  6. 激活指示器
  7. 帮助/错误/计数器文本
  8. 前缀/后缀/占位符(未显示)

帮助/错误/计数器文本没有图标,仅存在于容器的右侧(5)

你想要实现的可以是一个自定义实现。

在你的TextInputLayout下添加一个具有drawableStart属性的TextView。


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