Password visibility toggle in Android EditText

Password visibility toggle in Android EditText

We are familiar with password fields in any kind of application. We have also seen various apps where we can toggle password visibility while typing. In android, we use EditText with attribute ‘inputType=”textPassword”‘ in XML layout to implement password field. Question is how to implement that? Should we use some RelativeLayout with ImageView or something else? Wait, it’s not so hard. In this article we will discuss how to change password visibility in EditText.

LIBRARY for Password Visibility

We have used showhidepasswordedittext as dependency to achieve our objective. Add the following lines to your build.gradle(app level) in dependencies section. (Version may change from time to time. Check here for the latest release.)

This library is not available in Maven Central. So you can add it as a library module or use . Add the remote maven url to your build.gradle(project level) and synch your gradle.


So all dependencies related works are done. We have successfully added the library we require. Next we will create an Activity to make things work. Here we have created PasswordActivity but you can choose your own.

activity_password is the layout for PasswordActivity here. So the xml for activity_password would be like

In the above code you can see we have used ShowHidePasswordEditText(com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText) instead of just an EditText. This comes from the library we are using. But if you follow through to the deep, you will see it is nothing but the extended version of android.widget.EditText which is our very known EditText. Next run your application. You will see out like below

anroid password visibility

Feel free to comment or ask question if there is any query. If you liked this article spread it out. Subscribe to our newsletter to get more cool stuff.

Reference : showhidepasswordedittext by Scott Alexander-Bown

Tags :
Abhishek is a developer cum blogger working more than 6 years. He loves programming especially open stack technologies. He has decent knowledge in Android development, Wordpress, MongoDB, Node.js and so on. Beside this Abhishek finds himself busy in painting, front-end designing.

Follow Abhishek


Android Volley
Android Volley with example


Kotlin in Android Studio
Setting up Kotlin in Android Studio