当我改变 fragments 时,因为在屏幕上有一个 EditText 区域,我就使用下面的代码关闭键盘。如果键盘在屏幕上,我发现不了任何检测。
Activity activity = getActivity();
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
try
{
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
catch (Exception e)
{
}