0

I have a form with a few fields in my app in Xamarin.Forms. I need to provide text "Next" on the android soft keyboard and on tap of "Next" it should take me to next field.

My Code in customRenderer:

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

This sets the text on the keypad to "Next", but it will not take me to the next field.

I also tried writing some code in the OnAppearing() of xaml.cs:

entryOne.Completed+= (object sender, EventArgs e) =>
   {entryTwo.Focus(); };

Even this did not work.

Also the below code claims to show "Whatever" on the android soft keyboard button, but it shows the enum value of ImeAction, which in the below case will be "Next":

Control.SetImeActionLabel("Whatever",Android.Views.InputMethods.ImeAction.Next);
4

1 回答 1

1

Xamarin.FormsEntry提供了这个功能,您可以使用属性ReturnType来设置键盘和ReturnCommand编写代码,您想重点点击哪个条目。

在您的 xaml 中:

    <Entry   x:Name="txtUserName"
             ReturnCommand="{Binding loginCompleted}"
             ReturnType="Next"/>
    <Entry   x:Name="txtPassword"/>

在您的视图模型中:

      public ICommand loginCompleted
        {
            get { return new Command(loginCompletedEvent); }
        }

        /// <summary>
        /// Event for making the keyboard focus on password Entry
        /// </summary>
        private void loginCompletedEvent()
        {
            Entry entryPassword = m_view.FindByName<Entry>("txtPassword");
            entryPassword.Focus();
        }

希望这能解决您的问题。

于 2019-04-08T07:46:40.117 回答