What I'm looking for is a way to dismiss the keyboard while maintaining focus on the Entry field so an external keyboard can be used without giving up all that screen real estate.
I can't seem to implement the code in How to dismiss keyboard on button press in Xamarin Forms I'm calling it in the OnFocused of an Entry field.
Android.App.Application.Context as Activity;
is returning null Without the "as activity it works just fine, but I can't run
.CurrentFocus?.WindowToken;
on a Context.
This is what my code looks like.
[assembly: Dependency (typeof (KeyboardInteractions))] namespace namespace.Droid
{
public class KeyboardInteractions : IKeyboardInteractions
{
public void HideKeyboard()
{
var activity = Android.App.Application.Context as Activity;
var token = activity?.CurrentFocus?.WindowToken;
var i = (InputMethodManager)Android.App.Application.Context.GetSystemService(Context.InputMethodService);
if (token != null) {
i.HideSoftInputFromWindow(token, 0);
}
}
}
}