-4

I need to get the current keyboard instance in Xamarin.Android (which is currently visible in the application). Is there any way to achieve this?

Divakar
  • 514
  • 1
  • 9
  • 25

1 Answers1

-1

Alternatively, if you want to use a dependency service, the following will close the soft keyboard. Unfocus is probably safer though, as the below might not take into account any assumptions made within the XF framework:

iOS:

UIApplication.SharedApplication.KeyWindow.EndEditing(true);

Android:

InputMethodManager inputManager = (InputMethodManager)MainActivity.TheInstance.GetSystemService(Context.InputMethodService);
            var currentFocus = MainActivity.TheInstance.CurrentFocus;
            if (currentFocus != null)
            {
                inputManager.HideSoftInputFromWindow(currentFocus.WindowToken, HideSoftInputFlags.None);
            }

            MainActivity.TheInstance.Window.SetSoftInputMode(SoftInput.StateHidden);