Xamarin表单下一键键盘键盘在Droid应用程序中不起作用

时间:2015-09-15 09:22:12

标签: windows-phone-8 xamarin xamarin.android xamarin.forms

在我的Xamarin Forms应用程序中,我添加了用于在键盘上启用“下一步”和“完成”按钮的代码。但是下一次关键点击没有任何结果。但完成按键点击工作正常。以下是我的代码示例

渲染:

public class HACCPEntryRenderer :EntryRenderer
{
    protected override void OnElementChanged (ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged (e);

        if (Control != null) {


            if ((Element as MyEntry).IsLastItem)
                Control.ImeOptions = Android.Views.InputMethods.ImeAction.Done;
            else
                Control.ImeOptions = Android.Views.InputMethods.ImeAction.Next;

        }
    }

我在

背后的代码中添加了已完成的事件
private void Entry_Input_Completed(object sender , EventArgs args)
    {           
        nextEntry.Focus ();
    }   

请帮帮我

1 个答案:

答案 0 :(得分:0)

我不得不为此工作,我不得不使用消息中心来设置条目的重点(Android版本因为iOS工作正常)

自定义渲染器内部:

Control.ImeOptions = Android.Views.InputMethods.ImeAction.Next;
Control.SetImeActionLabel("Next", Android.Views.InputMethods.ImeAction.Next);

switch(entry.CustomImeAction){
    case ImeAction.Email:
        editText.EditorAction += (object sender, TextView.EditorActionEventArgs args) =>
        {
            MessagingCenter.Send<IEntryMessages>(this, "Email");
        };
        break;
    case ImeAction.Password:
        editText.EditorAction += (object sender, TextView.EditorActionEventArgs args) =>
        {
            MessagingCenter.Send<IEntryMessages>(this, "Password");
        };
        break;
}

在您的参赛作品/页面上:

 MessagingCenter.Subscribe<IEntryMessages> (this, "Email", (sender) => {
    Device.BeginInvokeOnMainThread (async () => {
        await Task.Run( () => Task.Delay( 1 ) );
        PasswordEntry.Focus();
    });
});

MessagingCenter.Subscribe<IEntryMessages> (this, "Password", (sender) => {
    Device.BeginInvokeOnMainThread (async () => {
        await Task.Run( () => Task.Delay( 1 ) );
        ConfirmPasswordEntry.Focus();
    });
});