Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

password toggle icon textinputlayout override error icon

I am using a password toggle to show and hide the password. And I do not want to use the custom drawable. But, when this edit text generate error it overrides the toggle password icon and unable to add padding or margin to that icon. If there is any solution to this, it will be a pleasure. This is the code I am using:

       <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:textColorHint="@color/white"
                app:passwordToggleEnabled="true"
                app:passwordToggleTint="@color/white">

                <EditText
                    android:id="@+id/et_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/white"
                    android:hint="@string/password"
                    android:imeOptions="actionDone"
                    android:inputType="textPassword"
                    android:maxLength="40"
                    android:maxLines="1"
                    android:textColor="@color/white"
                    android:textColorHint="@color/app_green_color" />

            </com.google.android.material.textfield.TextInputLayout>
like image 748
Saad Khan Avatar asked Nov 23 '25 04:11

Saad Khan


2 Answers

I had the same problem. I'm using TextInputLayout and

implementation 'com.google.android.material:material:1.2.1'

Any of the answers above didn't help me. This is the correct way to do it:

<com.google.android.material.textfield.TextInputLayout
 ...
 app:errorIconDrawable="@null">

    <com.google.android.material.textfield.TextInputEditText
     ...
     />
like image 158
Ozzini Avatar answered Nov 25 '25 18:11

Ozzini


Use the TextInputEditText instead of the EditText.

  <com.google.android.material.textfield.TextInputLayout
       app:endIconMode="password_toggle"
       app:endIconTint="@color/white"
       ...>

         <com.google.android.material.textfield.TextInputEditText
           android:inputType="textPassword"
           ../>

  </com.google.android.material.textfield.TextInputLayout>

Also (but it is not related to the issue) the attributes app:passwordToggleEnabled="true" and app:passwordToggleTint="@color/white" are now deprecated. Use app:endIconMode and app:endIconTint.

like image 35
Gabriele Mariotti Avatar answered Nov 25 '25 18:11

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!