ErrorIconDrawable in TextInputLayout does not show anything

Viewed 651

I am trying to set an icon in textInputLayout error like this :

enter image description here

I set this app:errorIconDrawable="@drawable/login_erroricon" in TextInputLayout but when i run app it does not show anything.

<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">

I also try it in the code but it does not appear anything :

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

Attention : text is ok but icon is disappear.

1 Answers

As the material.io documents states a TextInputLayout contains:

enter image description here

  1. Container
  2. Leading icon
  3. Label
  4. Input text
  5. Trailing icon
  6. Activation indicator
  7. Helper/error/counter text
  8. Prefix/suffix/placeholder (not shown)

There is no icon for Helper/Error/Counter Text, It only exists for Right side of the container (5)

What you want to achieve can be a custom implementation.

Add a TextView with drawableStart attribute under your TextInputLayout.

Related