弹出:
InputMethodManager im = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
消失:
InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);在Android中点击EditText的时候会弹出软键盘,这时候如果想隐藏软键盘或者填完内容后点其他的地方直接隐藏软键盘,可以按一下方法处理。
首先获得软键盘Manager
[java] view plain copy InputMethodManager manager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_DOWN){ if(getCurrentFocus()!=null && getCurrentFocus().getWindowToken()!=null){ manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } return super.onTouchEvent(event); }