获取edit焦点,打开和关闭软键盘
打开:
et_search.requestFocus();
et_search.setFocusable(true);
et_search.setFocusableInTouchMode(true);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_search, 0);
关闭:InputMethodManager imm1 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm1.hideSoftInputFromWindow(et_search.getWindowToken(), 0);
改变键盘输入法的状态,如果已经弹出就关闭,如果关闭了就强制弹出 :
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);