使用库后在 android 中隐藏软键盘

Hide soft keyboard in android after using library

我无法在我的代码中隐藏软键盘。我正在使用一些方法:

  1. 在java代码中:

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    
  2. 在清单中:

    android:windowSoftInputMode="stateHidden|adjustResize"
    

这对我不起作用。你能帮帮我吗?

P.S: 当我使用这个库时发生了 https://github.com/Quinny898/PersistentSearch

从 Activity 要隐藏软键盘的地方调用此方法(您可以将其放入不同的 class 并使用 class 名称作为其静态调用)

public static void hideSoftKeyboard(Activity activity) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (activity.getCurrentFocus() != null)
            inputMethodManager.hideSoftInputFromWindow(activity
                    .getCurrentFocus().getWindowToken(), 0);
    }