void OnPromptRequested(Page sender, PromptArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } AlertDialog alertDialog = new AlertDialog.Builder(Activity).Create(); alertDialog.SetTitle(arguments.Title); alertDialog.SetMessage(arguments.Message); var frameLayout = new FrameLayout(Activity); var editText = new EditText(Activity) { Hint = arguments.Placeholder, Text = arguments.InitialValue }; var layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent) { LeftMargin = (int)(22 * Activity.Resources.DisplayMetrics.Density), RightMargin = (int)(22 * Activity.Resources.DisplayMetrics.Density) }; editText.LayoutParameters = layoutParams; editText.InputType = arguments.Keyboard.ToInputType(); if (arguments.Keyboard == Keyboard.Numeric) { editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType); } if (arguments.MaxLength > -1) { editText.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(arguments.MaxLength) }); } frameLayout.AddView(editText); alertDialog.SetView(frameLayout); alertDialog.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(editText.Text)); alertDialog.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(null)); alertDialog.CancelEvent += (o, args) => { arguments.SetResult(null); }; alertDialog.Window.SetSoftInputMode(SoftInput.StateVisible); alertDialog.Show(); editText.RequestFocus(); }
void OnAlertRequested(Page sender, AlertArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } AlertDialog alert = new AlertDialog.Builder(Activity).Create(); alert.SetTitle(arguments.Title); alert.SetMessage(arguments.Message); if (arguments.Accept != null) { alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true)); } alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false)); alert.CancelEvent += (o, args) => { arguments.SetResult(false); }; alert.Show(); }