Skip to content

Instantly share code, notes, and snippets.

@esabook
Created May 14, 2019 03:53
Show Gist options
  • Save esabook/0679c78dfce3a3746c0d85ec30a34705 to your computer and use it in GitHub Desktop.
Save esabook/0679c78dfce3a3746c0d85ec30a34705 to your computer and use it in GitHub Desktop.
hide soft keyboard
/**
* @param v
*/
public static void hideKeyboard(View v) {
if (v == null || v.getContext() == null) return;
InputMethodManager imm = (InputMethodManager)
v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isAcceptingText()) {
imm.hideSoftInputFromWindow(v.getRootView().getWindowToken(), 0);
}
}
/**
* @param a
*/
public static void hideKeyboard(Activity a) {
hideKeyboard(a.getCurrentFocus());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment