最近做的項目是7.0的,隱藏軟鍵盤的時候,傳統的做法是在配置文件中設置android:windowSoftInputMode="stateAlwaysHidden"
實際運行后發現軟鍵盤依然會彈出來。7.0以前的版本沒有問題
解決方法:
public static void hideSoftInput(Context context, EditText edit) {
edit.clearFocus();
InputMethodManager inputManger = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManger.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}
2
public static void disableSoftInputFromAppearing(EditText editText) {
if (Build.VERSION.SDK_INT >= 11) {
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
} else {
editText.setRawInputType(InputType.TYPE_NULL);
editText.setFocusable(true);
}
}