一、方法一(若是輸入法在窗口上已經顯示,則隱藏,反之則顯示)java
[java] view plaincopyprint?app
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); ide
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); this
二、方法二(view爲接受軟鍵盤輸入的視圖,SHOW_FORCED表示強制顯示)spa
[java] view plaincopyprint?.net
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); orm
imm.showSoftInput(view,InputMethodManager.SHOW_FORCED); blog
[java] view plaincopyprint?ip
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //強制隱藏鍵盤 get
三、調用隱藏系統默認的輸入法
[java] view plaincopyprint?
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是當前的Activity)
四、獲取輸入法打開的狀態
[java] view plaincopyprint?
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();//isOpen若返回true,則表示輸入法打開