1. 隐藏软键盘的方法,代码如下
InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
2. 点击空白位置自动隐藏软键盘
需要重写onTouchEcent()
代码如下:
@Override public boolean onTouchEvent(MotionEvent event) {
if(null != this.getCurrentFocus()){
InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
return mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
}
return super .onTouchEvent(event);
}