Rajkiran Rajkiran - 5 months ago 92
Android Question

Programmatically change input type of the EditText from PASSWORD to NORMAL & vice versa

In my application, I have an

whose default input type is set to
by deault. It has a
to its right, which is when checked, changes the input type of that EditText to NORMAL PLAIN TEXT. Code for that is-


My problem is, when that CheckBox is unchecked it should again set the input type to PASSWORD. I've done it using-


But, the text inside that edittext is still visible. And for surprise, when I change the orienatation, it automatically sets the input type to PASSWORD and the text inside is bulleted (shown like a password).

Any way to achieve this?


Just for the people who are having same problem. Just add an extra attribute to that EditText programmatically and you are done.

password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

Also, make sure that the cursor is at the end of the text in the EditText. Because, when you change the input type, the cursor will be automatically set to the starting point. So I suggest to use the following code:

et_password.setInputType(InputType.TYPE_CLASS_TEXT |