I am currently showing softkeyboard using the following code
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im
I have tested and this is working:
...
//to show soft keyboard
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
//to hide it, call the method again
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
By the way, the second parameter of your code is not right, please have a look at here.
user942821's answer for hiding it works:
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
But this also works for me to hide it:
imm.toggleSoftInput(0, 0);
You might also want to try:
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
When using '0' in the first parameter sometimes the keyboard toggles on in the wrong places under weird circumstances that I haven't been able to figure out how to duplicate yet. I'm still testing this last example, but will update when I find out more.
See toggleSoftInput documentation page for more information.
Use this working code :
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
You could also try
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
This code hides the keyboard from inside onItemClick
of an AutoCompleteTextView
public void onItemClick(AdapterView<?> adapterViewIn, View viewIn, int indexSelected, long arg3) {
// whatever your code does
InputMethodManager imm = (InputMethodManager) getSystemService(viewIn.getContext().INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(viewIn.getApplicationWindowToken(), 0);
}
This works fine
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.hideSoftInputFromWindow(getWindow().getAttributes().token, 0);