在Xamarin.forms中使用编辑器标签时,在软键盘中将“下一个箭头键”更改为“完成”

时间:2018-10-11 15:08:38

标签: xamarin xamarin.forms

当编辑器字段突出显示时,我希望下一个箭头键说“完成”。

Here,In the image the Marked key 'Next arrow key' has to "Done"

我已经参考了一些与此相关的链接,但是在我的情况下似乎没有任何作用...这是一个这样的链接 Change return to be next/done key in Xamarin Forms Shared Project

在这里,它们正在扩展Entry属性,在本例中,当我尝试扩展Editor属性时,我必须扩展Editor属性,它没有显示任何错误,但键盘看起来像以前一样

我的代码是

public class PlaceholderEditorRenderer : EditorRenderer
{
    public PlaceholderEditorRenderer()
    {
    }

    protected override void OnElementChanged(
        ElementChangedEventArgs<Editor> e)
    {
        base.OnElementChanged(e);

        PlaceholderEditor placeHolderEditor = (PlaceholderEditor)this.Element;

        if (this.Control != null)
        {
            if (placeHolderEditor != null)
            {
                SetReturnType(placeHolderEditor);

                Control.EditorAction += (object sender, EditText.EditorActionEventArgs args) =>
                {
                    if (placeHolderEditor.ReturnKeyType == ReturnKeyTypes.Done)
                        placeHolderEditor.Unfocus();

                    // Call all the methods attached to custom_entry event handler Completed
                    placeHolderEditor.InvokeCompleted();
                };
            }
        }

        if (e.NewElement != null)
        {
            var element = e.NewElement as PlaceholderEditor;
            this.Control.Hint = element.Placeholder;
        }
    }

    protected override void OnElementPropertyChanged(
        object sender,
        PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (e.PropertyName == PlaceholderEditor.PlaceholderProperty.PropertyName)
        {
            var element = this.Element as PlaceholderEditor;
            this.Control.Hint = element.Placeholder;
        }
    }

    private void SetReturnType(PlaceholderEditor entry)
    {
        ReturnKeyTypes type = entry.ReturnKeyType;

        switch (type)
        {
            case ReturnKeyTypes.Go:
                Control.ImeOptions = ImeAction.Go;
                Control.SetImeActionLabel("Go", ImeAction.Go);
                break;
            case ReturnKeyTypes.Next:
                Control.ImeOptions = ImeAction.Next;
                Control.SetImeActionLabel("Next", ImeAction.Next);
                break;
            case ReturnKeyTypes.Send:
                Control.ImeOptions = ImeAction.Send;
                Control.SetImeActionLabel("Send", ImeAction.Send);
                break;
            case ReturnKeyTypes.Search:
                Control.ImeOptions = ImeAction.Search;
                Control.SetImeActionLabel("Search", ImeAction.Search);
                break;
            case ReturnKeyTypes.Done:
                Control.ImeOptions = ImeAction.Done;
                Control.SetImeActionLabel("Done", ImeAction.Done);
                break;
            default:
                Control.ImeOptions = ImeAction.Done;
                Control.SetImeActionLabel("Done", ImeAction.Done);
                break;
        }
    }
}

0 个答案:

没有答案