安卓隐藏键盘失效

直入主题:

第一种

第二种:

/**
 * 隐藏软键盘(只适用于Activity,不适用于Fragment)
 */
public static 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);
    }
}

第三种:

//view为接受软键盘输入的视图,SHOW_FORCED表示强制显示
public static void hideSoftKeyboard(Activity activity, View view) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
}

但是都无效,需要注意取消掉获取焦点的EditText控件的焦点

android:focusableInTouchMode="false"
android:focusable="false"

你可能感兴趣的:(项目问题)