I use an EditText to enter password. And a CheckBox to show password or not. Below function is the part:
public void ShowPassword() {
if (cb.isChecked()) {
password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
When it checked, it show password. But when it not checked, it does show stars. How to modify it to show star while the cb is not checked?
use app:passwordToggleEnabled = true; available from Android support library version 24.2.0.
I don't know exactly the specifics, but this code should work:
129
is the input type set when settingandroid:inputType="textPassword"
edit:
as mentioned in @user370305's answer,
129
is the value of the bitwise or operation when you doCall this method inside your
OnCheckedChangedListener
The
EditText
cursor resets its position after changing theInputType
that's why we add the last lineeditText.setSelection(editText.length())
I think you are using the wrong function. I make that way and work perfectly:
on the off chance that you are using Xamarin (Visual Studio Mac as it's now called) you can achieve it this way (I used a Switch)
Then on your Switch .click do something like this