Search code examples
androidandroid-softkeyboardandroid-4.0-ice-cream-sandwichdialog

Hide softkeyboard on dialog box loading in Android 4.0


I have an activity which opens up a dialog that contains edittexts on a button click. As soon as the dialog opens the softkeyboard shows. I want to prevent this. Only when I click on the edittext in the dialog should the softkeyboard appear. I am using Android 4.

Thanks in advance


Solution

  • This should work is any case:

    public void hideKeyboard() {
    
                mActivity.runOnUiThread(new Runnable() {
                    public void run() {
                        InputMethodManager inputManager = (InputMethodManager) mActivity
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        inputManager.hideSoftInputFromWindow(mActivity
                                .getCurrentFocus().getWindowToken(),
                                InputMethodManager.HIDE_NOT_ALWAYS);
                    }
                });
            }