android studio close keyboard code example
Example 1: How to programmatically hide Android soft keyboard
private void closeSoftKeyboard()
{
View v = this.getCurrentFocus();
if (v != null) {
InputMethodManager inputManager
= (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
Example 2: close keyboard android
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager =
(InputMethodManager) activity.getSystemService(
Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
activity.getCurrentFocus().getWindowToken(), 0);
}