如何在button
点击 Xamarin Android中隐藏和查看密码?
private void _viewPassword_Click(object sender, EventArgs e) {
EditText _editTextNew = FindViewById<EditText>(Resource.Id.editTxtPwd_signup);
if (_editTextNew.InputType== Android.Text.InputTypes.TextVariationPassword) {
_editTextNew.InputType = Android.Text.InputTypes.ClassText;
_editTextNew.SetSelection(_editTextNew.Text.Length);
}
else if(_editTextNew.InputType == Android.Text.InputTypes.ClassText) {
_editTextNew.InputType = Android.Text.InputTypes.TextVariationPassword;
_editTextNew.SetSelection(_editTextNew.Text.Length);
}
}
答案 0 :(得分:1)
您可以使用TextVariationVisiblePassword
,TextVariationPassword
与ClassText
一样使用。但为了确保满足您的条件,我建议使用全局Boolean
:
private void _viewPassword_Click(object sender, EventArgs e) {
if (_isPasswordHidden) {
_editText.InputType =
Android.Text.InputTypes.TextVariationVisiblePassword
| Android.Text.InputTypes.ClassText;
} else {
_editText.InputType =
Android.Text.InputTypes.TextVariationPassword
| Android.Text.InputTypes.ClassText;
}
_isPasswordHidden = !_isPasswordHidden;
}