android中点击空白处隐藏软键盘

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);
 }

 

posted @ 2015-12-22 15:54  鲸歌  阅读(181)  评论(0编辑  收藏  举报