Android: close keyboard

When I am entering text into EditText and then hitting Save Button I want the keyboard to close.


 closeSoftKeyboard(myEditText);
...
}
private void closeSoftKeyboard(View view) {
   InputMethodManager imm = (InputMethodManager)       getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
   imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

}


getActivity() is needed when you use it in Fragment.


As an Amazon Associate I earn from qualifying purchases.

No comments:

Post a Comment

Post Scriptum

The views in this article are mine and do not reflect those of my employer.
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
LinkedIn
Google Scholar

Popular Recent Posts

Most Popular Articles

apt quotation..