Skip to content

Instantly share code, notes, and snippets.

@Ankit-Slnk
Created February 23, 2022 16:18
Show Gist options
  • Save Ankit-Slnk/c2c214b959139abc887f5a63072a71fb to your computer and use it in GitHub Desktop.
Save Ankit-Slnk/c2c214b959139abc887f5a63072a71fb to your computer and use it in GitHub Desktop.
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
public static void showKeyboard(Activity activity, EditText et) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment