public static void AddToolbar(this TextView control, Entry entry, IKeyboardToolbar keyboardToolbar) { try { var previous = keyboardToolbar?.GetPrevious(); var next = keyboardToolbar?.GetNext(); if (keyboardToolbar == null || (previous == null && next == null)) { control.ImeOptions = ImeAction.Done; control.SetImeActionLabel("Done", ImeAction.Done); } else { if (previous == null) { control.ImeOptions = ImeAction.Next; control.SetImeActionLabel("Next", ImeAction.Next); control.EditorAction += (s, e) => { entry.Unfocus(); next.Focus(); }; } else if (next == null) { control.ImeOptions = ImeAction.Done; control.SetImeActionLabel("Done", ImeAction.Done); control.EditorAction += (s, e) => { entry.Unfocus(); }; } else { control.ImeOptions = ImeAction.Next; control.SetImeActionLabel("Next", ImeAction.Next); control.EditorAction += (s, e) => { entry.Unfocus(); next.Focus(); }; } } } catch { } }
static VisualElement GetNext(this IKeyboardToolbar keyboardToolbar) { return(keyboardToolbar.NextAction == null ? keyboardToolbar.Next : keyboardToolbar.NextAction()); }
static VisualElement GetPrevious(this IKeyboardToolbar keyboardToolbar) { return(keyboardToolbar.PreviousAction == null ? keyboardToolbar.Previous : keyboardToolbar.PreviousAction()); }
public static void AddToolbar(this UITextField textField, IKeyboardToolbar keyboardToolbar) { if (textField == null) { return; } try { textField.KeyboardAppearance = UIKeyboardAppearance.Dark; var toolbar = new UIToolbar(new RectangleF(0.0f, 0.0f, _display.Value.Width, 44.0f)) { TintColor = UIColor.White, BarStyle = UIBarStyle.Black, Translucent = true }; var spaceButton = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { textField.ResignFirstResponder(); }); var previous = keyboardToolbar?.GetPrevious(); var next = keyboardToolbar?.GetNext(); if (keyboardToolbar == null || (previous == null && next == null)) { toolbar.Items = new UIBarButtonItem[] { spaceButton, doneButton }; } else { if (previous == null) { toolbar.Items = new UIBarButtonItem[] { doneButton, spaceButton, new UIBarButtonItem("Next", UIBarButtonItemStyle.Bordered, delegate { next.Focus(); }) } } ; else if (next == null) { toolbar.Items = new UIBarButtonItem[] { spaceButton, new UIBarButtonItem("Prev", UIBarButtonItemStyle.Bordered, delegate { previous.Focus(); }), doneButton } } ; else { toolbar.Items = new UIBarButtonItem[] { doneButton, spaceButton, new UIBarButtonItem("Prev", UIBarButtonItemStyle.Bordered, delegate { previous.Focus(); }), new UIBarButtonItem("Next", UIBarButtonItemStyle.Bordered, delegate { next.Focus(); }) } }; } textField.InputAccessoryView = toolbar; } catch { } }