android 手動顯示與隱藏軟鍵盤HIDE_NOT_ALWAYS,android隱藏軟鍵盤
1、方法一(如果IME在視窗上已經顯示,則隱藏,反之則顯示)
[java] view plaincopyprint?
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
2、方法二(view為接受軟鍵盤輸入的視圖,SHOW_FORCED表示強制顯示)
[java] view plaincopyprint?
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);
[java] view plaincopyprint?
- imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //強制隱藏鍵盤
3、調用隱藏系統預設的IME
[java] view plaincopyprint?
- ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是當前的Activity)
4、擷取IME開啟的狀態
[java] view plaincopyprint?
- InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- boolean isOpen=imm.isActive();//isOpen若返回true,則表示IME開啟