【问题标题】:Xamarin Forms Next key click in keyboard is not working in Droid applicationXamarin Forms Next 键盘中的键单击在 Droid 应用程序中不起作用
【发布时间】:2015-09-15 23:53:48
【问题描述】:

在我的 Xamarin Forms 应用程序中,我添加了用于在键盘上启用 Next 和 Done 按钮的代码。但是在下一次按键点击时什么也没有发生。但是完成键单击工作正常。以下是我的代码示例

渲染:

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 ();
    }   

请帮帮我

【问题讨论】:

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


    【解决方案1】:

    我必须做一个 hack 才能工作,我必须使用消息中心来设置条目的焦点(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();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 2018-09-15
      • 1970-01-01
      • 2010-11-20
      • 2019-03-08
      • 2018-03-06
      • 1970-01-01
      相关资源
      最近更新 更多