Android隐藏软键盘

来源:互联网 发布:个人网站博客系统php 编辑:程序博客网 时间:2024/06/07 16:22

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);  }
原创粉丝点击