0

I use with "Action bar Sherlock". I want when touch on screen and show slide menu "keyboard is closed". i am so confused for this. what should i do?

  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, 0);
Mohammad
  • 15
  • 1
  • 7

1 Answers1

1

Try this method to hide keyboard when you need

 public void hideTypingKeyboard() {
        try {
            if(getCurrentFocus() != null) {
                   InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                   imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 }

EDIT:

 public static void hideEditTextKeyboard(InputMethodManager imm, EditText edittext) {
        if (edittext != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
        }
    }

I hope it helps!

Rajesh
  • 12,393
  • 4
  • 47
  • 76