AlertDialog关闭时键盘不会被隐藏
  我用我的类扩展了AlertDialog,显示了我的XML布局。  我不使用AlertDialog的标准按钮,我有我自己的OK和Cancel按钮。  他们的监听者调用dismiss() 。  问题是,如果我编辑EditText的内容,然后按下确定(这是一个Android 3.1平板电脑,键盘不阻止我与对话框交互),对话框将隐藏,但键盘不会,它会留在后台。  可能是什么原因以及如何解决它? 
这是我的对话框的构造函数,给出了这个想法:
public NetworkCameraParametersDialog(Context context ) {
        super(context);
        View content = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dialog, null);
        setView(content);
        Button btnOk = (Button) content.findViewById(R.id.btn_Ok);
        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                                // Some work
                dismiss();              
            }
        });
        Button btnClose = (Button) content.findViewById(R.id.btn_Close);
        btnClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
您可以强制使用软键盘隐藏:
    try {
        InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {}
上一篇: Keyboard is not being hidden when AlertDialog is dismissed
下一篇: Cannot hide Android soft keyboard even with inputmanager
