public override void Prompt(PromptConfig config) { Utils.RequestMainThread(() => { var activity = this.getTopActivity(); var txt = new EditText(activity) { Hint = config.Placeholder }; if (config.InputType != InputType.Default) txt.SetMaxLines(1); this.SetInputType(txt, config.InputType); var dialog = new AlertDialog .Builder(activity) .SetCancelable(false) .SetMessage(config.Message) .SetTitle(config.Title) .SetView(txt) .SetPositiveButton(config.OkText, (o, e) => config.OnResult(new PromptResult { Ok = true, Text = txt.Text }) ) .SetNegativeButton(config.CancelText, (o, e) => config.OnResult(new PromptResult { Ok = false, Text = txt.Text }) ).Create(); dialog.Window.SetSoftInputMode(SoftInput.StateVisible); dialog.Show(); }); }
public override void Prompt(PromptConfig config) { UIApplication.SharedApplication.InvokeOnMainThread(() => { var result = new PromptResult(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert); UITextField txt = null; dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => { result.Ok = true; result.Text = txt.Text.Trim(); config.OnResult(result); })); dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Default, x => { result.Ok = false; result.Text = txt.Text.Trim(); config.OnResult(result); })); dlg.AddTextField(x => { this.SetInputType(x, config.InputType); x.Placeholder = config.Placeholder ?? String.Empty; txt = x; }); this.Present(dlg); } else { var isPassword = config.InputType == InputType.Password; var dlg = new UIAlertView(config.Title ?? String.Empty, config.Message, null, config.CancelText, config.OkText) { AlertViewStyle = isPassword ? UIAlertViewStyle.SecureTextInput : UIAlertViewStyle.PlainTextInput }; var txt = dlg.GetTextField(0); this.SetInputType(txt, config.InputType); txt.Placeholder = config.Placeholder; dlg.Clicked += (s, e) => { result.Ok = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex); result.Text = txt.Text.Trim(); config.OnResult(result); }; dlg.Show(); } }); }