首先获得软键盘的对象
转自 http://blog.youkuaiyun.com/wbw1985/article/details/7695081
InputMethodManager imm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
然后注册空白处的touch事件
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
System.out.println("down");
if (LoginActivity.this.getCurrentFocus() != null) {
if (LoginActivity.this.getCurrentFocus().getWindowToken() != null) {
imm.hideSoftInputFromWindow(LoginActivity.this
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
return super.onTouchEvent(event);
}
转自 http://blog.youkuaiyun.com/wbw1985/article/details/7695081