Skip to content

Instantly share code, notes, and snippets.

@gibson-khs
Last active November 28, 2017 08:29
Show Gist options
  • Select an option

  • Save gibson-khs/56ce836aa39c675477d9ceb8b6cc59d4 to your computer and use it in GitHub Desktop.

Select an option

Save gibson-khs/56ce836aa39c675477d9ceb8b6cc59d4 to your computer and use it in GitHub Desktop.
public class KeyboardUtils {
public static void hideKeyboard(Context context) {
try {
((Activity) context).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
if ((((Activity) context).getCurrentFocus() != null) && (((Activity) context).getCurrentFocus().getWindowToken() != null)) {
((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment