how to hide keyboard after typing in EditText in android?
I have a EditText
and button aligned to parent's bottom.
When I enter text in it and press the button to save data, the virtual keyboard does not disappear.
Can any one guide me how to hide the keyboard?
Solution 1:
You might also want to define the imeOptions within the EditText. This way, the keyboard will go away once you press on Done:
<EditText
android:id="@+id/editText1"
android:inputType="text"
android:imeOptions="actionDone"/>
Solution 2:
This should work.
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
Just make sure that this.getCurrentFocus() does not return null, which it would if nothing has focus.
Solution 3:
mEtNumber.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do something, e.g. set your TextView here via .setText()
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
});
and in xml
android:imeOptions="actionDone"
Solution 4:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);