Android 隐藏软键盘方法

时间:2022-04-11 07:14:29
第一种:
public static void hideInput(Activity activity) {
View curFoc = activity.getCurrentFocus();
if (curFoc != null) {
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(curFoc.getWindowToken(), 0);
}
} 第二种:
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
}