2

I need to hide the soft keyboard in response to clicking a button. I saw some posts about this, and I tried it with:

InputMethodManager im = (InputMethodManager) getSystemService(
    Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);

That worked well. But now I have two EditText views. How can I now hide the soft keyboard, no matter wich EditText is selected? I tried it also with

InputMethodManager im = (InputMethodManager) getSystemService(
    Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);
im.hideSoftInputFromWindow(myEditText2.getWindowToken(), 0);

, but that didn't worked...

Thanks for your help!

EDIT: Found solution. Posted below.

3 Answers 3

6

Simply you dont need to point specific view. Im using this and works :)

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
Sign up to request clarification or add additional context in comments.

Comments

2

A solution is to not get the window token from the EditText, but from the buton wich hides the keyboard itselfs:

InputMethodManager im = (InputMethodManager) getSystemService(
    Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(hideKeyboardButton.getWindowToken(), 0);

Comments

1
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

You can "play" with the parameter to achieve whatever you want. Hope this helped!

1 Comment

Not exactly what I was searching for, but thank you anyways! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.