代码语言:javascript复制
public void hideSoftInput(Activity activity) {
// 关闭软键盘
if (activity.getCurrentFocus() != null) {
if (activity.getCurrentFocus().getWindowToken() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}