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

3

I created a login form in my application and would like to put the eye button so that it can display the characters of the login field, as shown:

Ihavealreadydonesomeresearchandtriedtoaddfunctionalityinmyapplication,butwithoutsuccess.

Myloginlayout

<TextViewandroid: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"/>
    
asked by anonymous 07.01.2018 / 18:26

1 answer

3

Change your code accordingly:

<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>
    
07.01.2018 / 18:38