You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow
, passing in the token of the window containing your focused view.
public static void hideKeyboard(Activity activity) {
View view = activity.findViewById(android.R.id.content);
if (view != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.HIDE_IMPLICIT_ONLY
as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down menu).
You can see other best Android Gists or offer your just here https://github.com/lopspower/BestAndroidGists 👍.
Showw!!