安卓中EditText點選空白處隱藏軟鍵盤
阿新 • • 發佈:2019-01-03
Android開發過程中,點選EditText會出現鍵盤,當我們輸入完畢時,還要點一下返回鍵才能隱藏軟鍵盤,重寫下面這個方法,只要點選空白處就可以隱藏軟鍵盤,很方便,很實用。
/** * 點選空白位置 隱藏軟鍵盤 */ public boolean onTouchEvent(MotionEvent event) { if (null != this.getCurrentFocus()) { InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); return mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); } return super.onTouchEvent(event); }