Show the password with EditText

前端 未结 12 895
旧时难觅i
旧时难觅i 2021-01-30 22:04

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()) {
          


        
12条回答
  •  生来不讨喜
    2021-01-30 22:38

    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)

     /// 
     /// Toggles the password.
     /// 
     /// Field.
     /// If set to true is checked.
     private void TogglePassword(TextView field, bool isChecked)
     {
          /// masks with password character
          if (isChecked)
          {
               field.TransformationMethod = new PasswordTransformationMethod();
          }
          /// unmasks password
          else
          {
               field.TransformationMethod = null;
          }
    

    Then on your Switch .click do something like this

    switch.Click += delegate {
                TogglePassword(textView, switch.Checked);
            };
    

提交回复
热议问题