Skip to content

Instantly share code, notes, and snippets.

@francisnnumbi
Created August 4, 2017 07:17
Show Gist options
  • Save francisnnumbi/5c709aeab1fc2427d7085424b4230b7b to your computer and use it in GitHub Desktop.
Save francisnnumbi/5c709aeab1fc2427d7085424b4230b7b to your computer and use it in GitHub Desktop.
Do you want to hide your soft keyboard programmatically? For example, when you click a button or when you press ENTER (for single line editText). This snippet method is all you need. Call it and pass in any view available (layout, textView, editText, button,...)
private void hideKeyboard(View v) {
try {
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} catch (Exception e) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment