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();//isOpen若返回true,則表示輸入法打開
以上所述是針對Android 顯示和隱藏軟鍵盤的方法(手動),希望對大家有所幫助。