I would like my application to force the cellphone to close whenever the user presses a button (above and next to the edit).
I would like my application to force the cellphone to close whenever the user presses a button (above and next to the edit).
Within the click of the button, in the onClickListener, put this code:
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
if(imm.isActive())
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
This will cause the device's virtual keyboard to close.
Call this method:
/**
* Esconda o teclado
*/
public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
/**
* Mostre o teclado
*/
public void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
Based on this excellent SOen response: link