问题
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