密码EditText在Xamarin.Android中不起作用

时间:2018-06-27 14:10:37

标签: c# android xamarin xamarin.android dialog

将EditText添加到对话框并将其输入类型设置为密码不起作用。字母保留为纯文字。

    LinearLayout layout = new LinearLayout(this);
            layout.Orientation = Orientation.Vertical;
            EditText txtUsername = new EditText(this);
            txtUsername.Hint = "Username";
            layout.AddView(txtUsername);

            EditText txtPassword = new EditText(this);
            txtPassword.Hint = "Password";
            txtPassword.InputType = Android.Text.InputTypes.TextVariationPassword;
            layout.AddView(txtPassword);

            var alert = new Android.Support.V7.App.AlertDialog.Builder(this);
            alert.SetTitle("Login");
            alert.SetView(layout);
            alert.SetPositiveButton("Submit", (senderAlert, args) =>
            {
                var username = txtUsername.Text;
                var password = txtPassword.Text;

            });
            alert.SetNegativeButton("Cancel", (senderAlert, args) =>
            {

            });
            Dialog dialog = alert.Create();
            dialog.Show();

2 个答案:

答案 0 :(得分:0)

尝试使用“ IsPassword”属性。

txtPassword.IsPassword = true;

答案 1 :(得分:0)

txtPassword.InputType =
Android.Text.InputTypes.TextVariationPassword | Android.Text.InputTypes.ClassText;