我需要在Xamarin.Android(当前在应用程序中可见)中获取当前的键盘实例。有什么办法可以做到这一点?
答案 0 :(得分:-1)
或者,如果要使用依赖项服务,则以下操作将关闭软键盘。不过,不集中可能更安全,因为以下内容可能未考虑XF框架内做出的任何假设:
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);