今天整理了一下Android下對IME的操作:具體如下
一、開啟IME視窗:
[java]
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// 接受軟鍵盤輸入的編輯文本或其它視圖
imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// 接受軟鍵盤輸入的編輯文本或其它視圖
imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);二、關閉出入法視窗
[java]
nputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);<DIV style="LINE-HEIGHT: 26px; FONT-FAMILY: Arial; COLOR: rgb(51,51,51); FONT-SIZE: 14px" id=_mcePaste>//接受軟鍵盤輸入的編輯文本或其它視圖</DIV><P style="LINE-HEIGHT: 26px; FONT-FAMILY: Arial; COLOR: rgb(51,51,51); FONT-SIZE: 14px">inputMethodManager</P><DIV style="LINE-HEIGHT: 26px; FONT-FAMILY: Arial; COLOR: rgb(51,51,51); FONT-SIZE: 14px" id=_mcePaste>.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);</DIV>
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開啟則關閉,如果沒開啟則開啟
[java]
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);四、擷取IME開啟的狀態
[java]
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
//isOpen若返回true,則表示IME開啟
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
//isOpen若返回true,則表示IME開啟