How do I dismiss the keyboard when a button is pressed?
The solution above doesn't work for all device and moreover it's using EditText as a parameter. This is my solution, just call this simple method:
private void hideSoftKeyBoard() {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if(imm.isAcceptingText()) { // verify if the soft keyboard is open
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}