protected void hideSoftKeyboard() { if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
之前一直是 这个方法,折叠软键盘的,但是今天发现,不好用了,折不回去,折腾了一下,
发现是 Manifest 中,windowSoftInputMode 的值是stateHidden ,修改成 stateAlwaysHidden,
android:windowSoftInputMode="stateAlwaysHidden"
就能折叠了,原因未知,不知道是不是与我使用的布局有关,使用了CollapsingToolbarLayout,EditText 是放在 CollapsingToolbarLayout 里面的。