是)我有的:
我有一个自定义类MyEntry
派生自 Android 和 iOS 的Xamarin.Forms.Entry
自定义渲染器类MyEntryRenderer
。
我想要的是:
ImeOptions
我想通过打开Android
和ReturnKeyType
打开将键盘的“输入”按钮更改为“搜索”按钮iOS
(参见示例代码)。当我按下更改后的“搜索”按钮时,MyEntry.Completed
应该调用该事件(就像之前按下未更改的“输入”按钮时一样。
真正发生的事情:
代码按iOS
预期工作。但是Android
什么都没有发生。该事件不会被调用。
我的问题:
我怎样才能实现我上面描述的Android
?
示例代码:
应用程序.cs:
namespace CustomEntry
{
public class App
{
public static Page GetMainPage()
{
MyEntry entry = new MyEntry {
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Placeholder = "Enter some text"
};
entry.Completed += delegate {
Console.WriteLine("Completed");
};
return new ContentPage {
Content = entry,
};
}
}
}
我的条目.cs:
namespace CustomEntry
{
public class MyEntry:Entry
{
}
}
MyEntryRenderer.cs (Android):
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace CustomEntry.Android
{
public class MyEntryRenderer:EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null) {
Control.ImeOptions = global::Android.Views.InputMethods.ImeAction.Search;
}
}
}
}
MyEntryRenderer.cs (iOS):
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace CustomEntry.iOS
{
public class MyEntryRenderer:EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null) {
Control.ReturnKeyType = UIReturnKeyType.Search;
}
}
}
}