How to add the eye to display the password in Android Studio?

Asked

Viewed 2,372 times

3

I created a login form in my application and would like to put the eye button so that you can display the characters of the login field, as shown in the screenshot: inserir a descrição da imagem aqui

I’ve done some research and tried to add functionality to my application, but without success.

My login layout

<TextView
    android:id="@+id/textView1"
    android:layout_width="333dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/matricula"
    android:fontFamily="monospace"
    android:text="Senha:"
    android:textColor="#fff9ff"
    android:textSize="16dp"
    android:layout_centerHorizontal="true"/>

<android.support.design.widget.TextInputLayout
    android:id="@+id/password_til"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_marginTop="300dp">

    <EditText
        android:id="@+id/senha"
        android:layout_width="330dp"
        android:background="@drawable/round"
        android:padding="10dp"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:inputType="numberPassword"
        android:layout_marginTop="330dp" />

</android.support.design.widget.TextInputLayout>
<Button
    android:id="@+id/logar"
    android:layout_width="333dp"
    android:layout_height="wrap_content"
    android:textAlignment="center"
    android:textSize="16dp"
    android:layout_marginTop="366dp"
    android:text="Acessar"
    android:textColor="#0684ec"
    android:layout_centerHorizontal="true"/>

1 answer

4


Change your code for this:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="300dp"
    android:gravity="center"
    app:passwordToggleEnabled="true"
    app:passwordToggleTint="@color/colorPrimary">

    <EditText
        android:id="@+id/senha"
        android:layout_width="330dp"
        android:background="@drawable/round"
        android:padding="10dp"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:inputType="numberPassword"
        android:layout_marginTop="330dp" />

</android.support.design.widget.TextInputLayout>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.