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?
Asked
Active
Viewed 485 times
-4
-
2What are your trying to achieve by getting access to the keyboard? – BenCamps Dec 14 '18 at 16:33
1 Answers
-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);

Tehseen Mushtaq
- 27
- 4