A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
in my OnFieldTapped I forward the tapped event to the ContentPage or to any other element, to let the system close the software keyboard.
For android, you can use inputMethodManager, then hide keyboard by inputMethodManager.HideSoftInputFromWindow method.
Please create a follow static class in the MainActivity.cs file or create a new class file in the Platform/Android folder.
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Views.InputMethods;
public static partial class KeyboardHelper
{
public static void HideKeyboard()
{
var context = Platform.AppContext;
var inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager;
if (inputMethodManager != null)
{
var activity = Platform.CurrentActivity;
var token = activity.CurrentFocus?.WindowToken;
inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);
activity.Window.DecorView.ClearFocus();
}
}
}
Then you can hide keyboard in the layout background code like following code.
#if ANDROID
KeyboardHelper.HideKeyboard();
#endif