In my application, I have an EditText
whose default input type is set to android:inputType="textPassword"
by deault. It has a CheckBox
to its right, which is when checked, changes the input type of that EditText to NORMAL PLAIN TEXT. Code for that is
password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
My problem is, when that CheckBox is unchecked it should again set the input type to PASSWORD. I've done it using-
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
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?
I change the input type on my checkbox, so on my
OnCheckedChangeListener
i do:And it finally worked.
Seems like a boolean problem with
TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
. Invert the flag and it should fix the problem.In your case:
final int[] count = {0};
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:
When using Data Binding, you can make use of the following code
If using Kotlin,
password.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
some dynamic situation
holder.edit_pin.setInputType(InputType.TYPE_CLASS_NUMBER);
will not work so better use both like thatNote : this is suitable for when you are using dynamic controls like using arrayaapter
use this code to change password to text and vice versa
for full sample code refer http://www.codeproject.com/Tips/518641/Show-hide-password-in-a-edit-text-view-password-ty
This worked for me: