How do I dismiss the keyboard when a button is pressed?
public static void hideSoftInput(Activity activity) {
try {
if (activity == null || activity.isFinishing()) return;
Window window = activity.getWindow();
if (window == null) return;
View view = window.getCurrentFocus();
//give decorView a chance
if (view == null) view = window.getDecorView();
if (view == null) return;
InputMethodManager imm = (InputMethodManager) activity.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null || !imm.isActive()) return;
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
} catch (Throwable e) {
e.printStackTrace();
}
}