隐藏当前Activity的软键盘

亲测有用

/**
 * 隐藏软键盘(只适用于Activity,不适用于Fragment)
 */
public void hideSoftKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

你可能感兴趣的:(键盘)