Edit text Password Toggle Android

(updated for AndroidX)

Since the Support Library v24.2.0. you can achivie this very easy

What you need to do is just:

  1. Add the design library to your dependecies

     dependencies {
         implementation "com.google.android.material:material:1.2.1"
     }
    
  2. Use TextInputEditText in conjunction with TextInputLayout

     <com.google.android.material.textfield.TextInputLayout
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:id="@+id/etPasswordLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:passwordToggleEnabled="true">
    
         <android.support.design.widget.TextInputEditText
             android:id="@+id/etPassword"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="@string/password_hint"
             android:inputType="textPassword"/>
     </com.google.android.material.textfield.TextInputLayout>
    

passwordToggleEnabled attribute will make the password toggle appear

  1. In your root layout don’t forget to add xmlns:app="http://schemas.android.com/apk/res-auto"

  2. You can customize your password toggle by using:

app:passwordToggleDrawable – Drawable to use as the password input visibility toggle icon.
app:passwordToggleTint – Icon to use for the password input visibility toggle.
app:passwordToggleTintMode – Blending mode used to apply the background tint.

More details in TextInputLayout documentation.

enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)