Xamarin Show Keyboard and Focus on an Entry Field

a 夏天 提交于 2021-02-13 17:34:03

问题


I am using Xamarin.Android and I have a Dialog with Xamarin.Forms.Entry field in it.

How do I show keyboard and give focus to this Entry field when dialog is displayed?

I am using a device, not an emulator.


回答1:


Can you try this,

dialog.Appearing += (object sender, System.EventArgs e) => yourEntry.Focus ();

When you focus to the entry, Keyboard will be shown by default

Here is the sample, i have tried to show keyboard in button click

<StackLayout>
    <Entry x:Name="entry" HeightRequest="50" WidthRequest="100" />
    <Button Text="Show" Clicked="Handle_Clicked" HeightRequest="50" WidthRequest="100" />
</StackLayout>

void Handle_Clicked(object sender, System.EventArgs e)
{
   entry.Focus();
}


来源:https://stackoverflow.com/questions/44712783/xamarin-show-keyboard-and-focus-on-an-entry-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!