1

我已经研究了很多关于 SO 的答案,并提出了以下代码来在我的对话框弹出时显示键盘:

final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Title");
    final EditText input = new EditText(this);
    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean focused) {
            alertDialog
                    .getWindow()
                    .setSoftInputMode(
                            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        }
    });
    input.setFocusable(true);
    input.requestFocus();
    alertDialog.setView(input);

            alertDialog.show();

对话框显示,但键盘没有弹出。如果这有所不同,这一切都在 onTouch(...) 方法中。

我的应用程序仅是横向模式。我发现在纵向模式下,它正在显示。为什么是这样?

任何帮助表示赞赏。

4

1 回答 1

0

看起来是横向模式让我失望了。以下代码立即解决了这个问题:

imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
                        InputMethodManager.HIDE_IMPLICIT_ONLY);
                imm.showSoftInput(input, InputMethodManager.SHOW_FORCED);
                alertDialog
                        .getWindow()
                        .setSoftInputMode(
                                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
于 2013-03-31T20:54:09.597 回答