android - Why is Setting ImeOptions to Next in custom renderer of Xamarin.forms not taking me to next field in Android
问题描述
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);
解决方案
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();
}
希望这能解决您的问题。
推荐阅读
- lua - 使用 FFI 将二进制数据读取为 Lua 数
- vb.net - 创建 AS400 类以在 vb.net 应用程序中实现
- dart - 飞镖类中的冒号是什么意思?
- html - 使用 R 进行网页抓取 - 非 HTML 内容 - Firebase 生成的应用程序
- python - Python 中的 ARIMA 模型
- java - 如何使用 setter 和 getter 函数实现线程安全类,其中使用 setter 的频率远高于 getter
- python - 想要基于生成绘图的函数创建动画
- asp.net - 如何运行 ASP.Net Core 可执行文件?
- assembly - 你能在一个汇编操作中检查一个字节上的标志,并检索剩余的 7 位整数值吗?
- java - 在下一个/拆分或新行中显示消息