Falko Falko - 1 month ago 9
Android Question

Xamarin.UITest on Android: Dismiss keyboard with Entry.Completed

I'm testing a Xamarin.Forms app with an

Entry
element. I'd like to enter some text and dismiss the keyboard raising the
Entry.Completed
event. On iOS this is working nicely with
IApp.PressEnter
. On Android, however, this only inserts another whitespace.

How can I dismiss the keyboard such that
Entry.Completed
is raised?

I could imagine invoking a backdoor method or executing methods on the native views, but I couldn't get it to work, yet. Do you know how to raise
Entry.Completed
programatically from within Xamarin.Forms or Xamarin.Android?

Answer

Oh, I found a solution and it's rather trivial.

While the IApp interface has no method that is dismissing the keyboard and raising Entry.Completed on Android, there is AndroidApp.PressUserAction() for the desired purpose. So we can write:

(app as iOSApp)?.PressEnter();
(app as AndroidApp)?.PressUserAction();
Comments