Android关闭输入软键盘无效的问题

Android关闭输入软键盘无效的问题

1.Android 输入软键盘打开的方法

    View view = getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
        }

2.Android输入软键盘关闭的方法:

    View view = getCurrentFocus();
        if (view != null) {
            ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

3.遇到的问题

有时候,在关闭软件盘时出现 无效 的情况。

4.解决方式

修改Activity的windowSoftInputMode 为 :stateAlwaysHidden
     android:windowSoftInputMode="stateAlwaysHidden"

你可能感兴趣的:(android基础)