0

I used a Material TextInputLayout to show errors when user inputs wrong values. Although, the error logic is working fine, the error displays in a pop-up like this instead of being shown like this under the layout. Can anyone kindly explain what I am doing wrong. This is how I am creating EditText in the layout xml file:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/password_layout_signup_page"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginEnd="32dp"
        app:errorEnabled="true"
        app:passwordToggleEnabled="true"
        android:layout_below="@id/email_layout_signup_page">
 <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/password_edit_signup_page"
            style="@style/Body2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/lock_icon"
            android:drawablePadding="8dp"
            android:drawableTint="@color/hint_gray"
            android:ems="10"
            android:hint="@string/password_asteriks"
            android:inputType="textPassword" />
    </com.google.android.material.textfield.TextInputLayout>

And this is how I am setting errors in the corresponding .kt file:

passwordEditText.setError("Be at least 8 characters",null)
Yahya
  • 13
  • 6

1 Answers1

0

Set error on TextInputLayout instead of TextInputEditText

so try this :

password_layout_signup_page.setError("Be at least 8 characters")
nimi0112
  • 2,065
  • 1
  • 18
  • 32
  • Thanks a lot @nimi0112. stackoverflow is not letting me accept your answer within 5 minutes. As soon as the time limit finishes, I will accept it. – Yahya May 19 '20 at 01:24
  • @Yahya if you want to change the error color in the entire app use this https://stackoverflow.com/a/42018351/6549598 . If you want to change color at only 1 place go with this https://stackoverflow.com/a/30953551/6549598 – nimi0112 May 19 '20 at 01:28
  • Brother thanks a lot......God Bless You – Yahya May 19 '20 at 01:37