Eye icon in edit Text field in Android App

Ansar Ali
1 min readFeb 7, 2021

--

To implement eye icon in your app we should add dependency

Add dependency

  • Add material design in your build.gradle(app) in the dependency section.
  • you will find build.gradle (app) in app/Gradle Scripts/build.gradle(Module:app).
dependencies {
implementation 'com.google.android.material:material:1.3.0'
}
  • After it Sync your project, Syncing will take some time Because it will download some dependency.

#After finishing Sync (Building app)

Follow these steps

  • Call TextInputLayout component.
  • Declare height and width of layout, Add component what do you want.
  • To add eye icon in edit Text field

# add attribute passwordToggleEnabled, It should be true than we can see the eye icon.

app:passwordToggleEnabled="true"

# add color of eye icon , call passwordToggleTint and declare your desire color.

You can get reference from below.

<com.google.android.material.textfield.TextInputLayout
android:layout_width="300dp"
android:layout_height="60dp"
android:id="@+id/layout_password"
app:passwordToggleTint="@color/colorPrimary"
app:passwordToggleEnabled="true">

<EditText
android:id="@+id/password_editText"
android:layout_width="match_parent"
android:layout_height="45dp"
android:paddingLeft="5dp"
android:inputType="textPassword"
android:textSize="16sp"/>

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

Note:- Make sure your dependency will completed.

I hope it will help full

Thanks…

--

--

Ansar Ali
Ansar Ali

Written by Ansar Ali

Flutter and Android app developer.

No responses yet