1、方法一(如果輸入法在窗口上已經顯示,則隱藏,反之則顯示)
-
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
2、方法二(view爲接受軟鍵盤輸入的視圖,SHOW_FORCED表示強制顯示)
-
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-
imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);
-
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
3、調用隱藏系統默認的輸入法
-
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是當前的Activity)
4、獲取輸入法打開的狀態
-
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
-
boolean isOpen=imm.isActive();