How to close/hide the Android soft keyboard programmatically? - Stack Overflow
Mon Oct 31 2022 06:15:48 GMT+0000 (Coordinated Universal Time)
Saved by
@Moodz
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);
}
content_copyCOPY
https://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard-programmatically
Comments