When touch out of the edit text's range, the soft keyboard will be closed automatically in Android.
Last active
November 8, 2016 08:34
-
-
Save pokk/e975d40def108a0e67a29c065f394f57 to your computer and use it in GitHub Desktop.
Hide soft keyboard when clicking the outside of EditText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* When touch out of the edit text's range, the soft keyboard will be closed automatically. | |
*/ | |
@Override | |
public boolean onTouchEvent(MotionEvent event) | |
{ | |
InputMethodManager manager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); | |
if(event.getAction() == MotionEvent.ACTION_DOWN) | |
{ | |
if(getCurrentFocus()!= null && getCurrentFocus().getWindowToken()!= null) | |
{ | |
manager.hideSoftInputFromWindow(getCurrentFocus().InputMethodManager.HIDE_NOT_ALWAYS); | |
} | |
} | |
return super.onTouchEvent(event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment