【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);
	}
相關文章
相關標籤/搜索