今天整理了一下Android下對IME的操作:具體如下
一、開啟IME視窗:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);// 接受軟鍵盤輸入的編輯文本或其它視圖imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);
二、關閉出入法視窗
nputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);//接受軟鍵盤輸入的編輯文本或其它視圖inputMethodManager
.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);
三、如果IME開啟則關閉,如果沒開啟則開啟
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
四、擷取IME開啟的狀態
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);boolean isOpen=imm.isActive();//isOpen若返回true,則表示IME開啟