android 完美隐藏软键盘

2023-02-10 19:13:33 浏览数 (1)

代码语言: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);
			}
		}
	}

0 人点赞