在Android 4.0中加载对话框框中隐藏软键盘

时间:2012-12-06 08:00:39

标签: android android-softkeyboard android-4.0-ice-cream-sandwich dialog

我有一个activity,会在dialog点击时打开edittexts buttondialog。只要softkeyboard打开edittext节目即可。我想阻止这个。只有当我点击dialog中的softkeyboard时才会显示{{1}}。我使用的是Android 4。

提前致谢

3 个答案:

答案 0 :(得分:3)

要实现此目的,请在调用dialog.Show():

之前设置软输入模式
// Build and create your dialog.
AlertDialog dialog = new AlertDialogBuilder(...).create();

// Hide soft keypad by default (will be displayed when user touches any edit field).
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

// Show the dialog.
dialog.show();

答案 1 :(得分:0)

这应该适用于任何情况:

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);
                }
            });
        }

答案 2 :(得分:-1)

将这个添加到你的Manifest就是你要做的所有事情:

android:windowSoftInputMode =“stateHidden”

简单,但万一有人在这里看

:)