Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide soft keyboard after dialog dismiss

I want to hide soft keyboard after AlertDialog dismiss, but it's still visible. Here is my code:

alert = new AlertDialog.Builder(MyActivity.this); imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  alert.setOnDismissListener(new DialogInterface.OnDismissListener() {      @Override     public void onDismiss(DialogInterface dialog) {         imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);     } }); 
like image 590
Dmytro Zarezenko Avatar asked Jul 24 '12 15:07

Dmytro Zarezenko


People also ask

How do I hide my soft keyboard?

Hiding the Soft Keyboard Programmatically You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.

How do I hide my keyboard from clicking?

To hide keyboard, use the following code. InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow(v. getApplicationWindowToken(),0);


2 Answers

In Manifest xml

android:windowSoftInputMode="stateAlwaysHidden" 

It will automatically hide soft keyboard on Dismiss of Dialog

like image 98
Rajeshwar Avatar answered Sep 18 '22 18:09

Rajeshwar


I met the same problem. Solved it by doing like this. It doesn't need any reference:

imm.hideSoftInputFromWindow(getWindow().getDecorView()                 .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
like image 21
NordicShaw Avatar answered Sep 19 '22 18:09

NordicShaw