隱藏軟鍵盤方法
阿新 • • 發佈:2018-12-11
/** * 隱藏鍵盤 * * @param context * @param view */ public static void hideSoftInput(Context context, View view) { InputMethodManager imm = (InputMethodManager) IMApp.getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (view == null) { imm.toggleSoftInput(0, InputMethodManager.RESULT_HIDDEN); } else { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //強制隱藏鍵盤 } } /** * 判斷輸入法是否顯示 * * @param context * @return */ public static boolean getSoftInputState(Activity context) { return context.getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED; }