1、打開輸入法窗口:java
/** * 動態顯示軟鍵盤 * * @param context 上下文 * @param edit 輸入框 */ public static void showSoftInput(Context context, EditText edit) { edit.setFocusable(true); edit.setFocusableInTouchMode(true); edit.requestFocus(); InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(edit, 0); }
2、關閉出入法窗口git
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
/** * 隱藏軟鍵盤 */ public static void hideKeyboard(Activity c) { try { InputMethodManager imm = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(c.getCurrentFocus().getWindowToken(), 0); } catch (NullPointerException e) { Log.e("hideKeyboard", e.toString()); } }
3、若是輸入法打開則關閉,若是沒打開則打開ide
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
4、獲取輸入法打開的狀態工具
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); boolean isOpen=imm.isActive(); //isOpen若返回true,則表示輸入法打開
鍵盤相關工具類:this