Below I am writing a method that will hide the soft keyboard in android.
I just use hideSoftInputFromWindow() method of InputMethodManager in this method.
public static void hideKeyboard(Activity activity) {
//start with an 'always hidden' command for the activity's window
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//now tell the IMM to hide the keyboard FROM whatever has focus in the activity
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View currentFocusedView = activity.getCurrentFocus();
if (currentFocusedView != null) {
inputMethodManager.hideSoftInputFromWindow(currentFocusedView.getWindowToken(), 0);
}
}
0 Comment(s)