Android点击空白区域隐藏键盘

2015-05-21 0 706
Android点击空白区域隐藏键盘
/**
	 * 点击空白区域隐藏键盘.
	 * @param event the event
	 * @return true, if successful
	 */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			if (EBDocuSearchActivity.this.getCurrentFocus() != null) {
				if (EBDocuSearchActivity.this.getCurrentFocus().getWindowToken() != null) {
					imm.hideSoftInputFromWindow(EBDocuSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
				}
			}
		}
		return super.onTouchEvent(event);
	}
/**隐藏键盘 */
	protected void hideInputKeyboard(View v) {
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
	}

	/**弹起键盘 */
	protected void showInputKeyboard(View v) {
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.showSoftInput(v, 0);
	}

遇见资源网 java Android点击空白区域隐藏键盘 http://www.ox520.com/9338.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务