Search code examples
androidkeyboardandroid-softkeyboardwindow-soft-input-mode

Not able to hide default soft keyboard programatically in Nexus 7 tab


I am working on an app where I need to open my own custom soft keyboard for text input.To do that I am disabling the default soft keyboard and enabling the custom one. It works fine on Jelly Bean version. However when I run the same code on Nexus 7 Tab Kitkat version it does not hide the default soft keyboard. I am using the following code for hiding the default soft Keyboard:Any idea it his not working on Kit Kat version on Nexus 7 tab?? I have researched a lot but I have not been able to figure it out.

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

Thanks in advance


Solution

  • You can try the following:

    public void hideKeyboard(Activity context, View v) {
        InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }