View view = getWindow().peekDecorView();
if (view !=null) {
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
隱藏軟鍵盤 ?
? ? inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
顯示軟鍵盤?
inputMethodManager.showSoftInput(view,InputMethodManager.SHOW_FORCED);?
}
上面的方法又是不管用,原因暫時(shí)沒找到,可以用這個(gè):
顯示鍵盤
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
隱藏鍵盤
InputMethodManager imm = (InputMethodManager) mContext .getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
軟鍵盤按鍵
actionNone : 回車鍵,按下后光標(biāo)到下一行
actionGo : Go,
actionSearch : 放大鏡
actionSend : Send
actionNext : Next
actionDone : Done,確定/完成,隱藏軟鍵盤,即使不是最后一個(gè)文本輸入框
android:imeoptions="actionSearch"
EditText.setOnEditorActionListener設(shè)置監(jiān)聽
@Override
? ? public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
? ? ? ? boolean isOK = true;
? ? ? ? switch (actionId) {
? ? ? ? ? ? case EditorInfo.IME_ACTION_NONE:
? ? ? ? ? ? ? ? Toast.makeText(mContext, "點(diǎn)擊-->NONE", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case EditorInfo.IME_ACTION_GO:
? ? ? ? ? ? ? ? Toast.makeText(mContext, "點(diǎn)擊-->GO", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case EditorInfo.IME_ACTION_SEARCH:
? ? ? ? ? ? ? ? Toast.makeText(mContext, "點(diǎn)擊-->SEARCH", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case EditorInfo.IME_ACTION_SEND:
? ? ? ? ? ? ? ? Toast.makeText(mContext, "點(diǎn)擊-->SEND", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case EditorInfo.IME_ACTION_NEXT:
? ? ? ? ? ? ? ? Toast.makeText(mContext, "點(diǎn)擊-->NEXT", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? default:
? ? ? ? ? ? ? ? isOK = false;
? ? ? ? ? ? ? ? break;
? ? ? ? }