通过调用系统服务来隐藏键盘的一种处理方法:
// 获取InputMethodManager实例
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
// 获取当前Focus的View
View currentFocus = getCurrentFocus();
if (currentFocus != null) {
// 隐藏键盘
inputMethodManager.hideSoftInputFromWindow(
currentFocus.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS
);
}
}