android点击空白区域隐藏软键盘的实现

代码如下:

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		InputMethodManager imm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		// TODO Auto-generated method stub
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			System.out.println("down");
			if (MainActivity.this.getCurrentFocus() != null) {
				if (MainActivity.this.getCurrentFocus().getWindowToken() != null) {
					imm.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(),
							InputMethodManager.HIDE_NOT_ALWAYS);
				}
			}
		}
		return super.onTouchEvent(event);
	}


你可能感兴趣的:(android)