TextInputLayout中的ErrorIconDrawable不显示任何内容

问题描述 投票:3回答:1

我正在尝试在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)

注意:文字可以,但是图标消失。

android android-layout material-design android-textinputlayout material-components-android
1个回答
2
投票

由于material.io文档声明了TextInputLayout包含:

enter image description here

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

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

您想要实现的可以是custom实现。

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

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