如何在PopupWindow上显示键盘?

时间:2010-10-12 13:31:55

标签: android android-softkeyboard popupwindow

我正在使用PopupWindow课程,PopupWindow我有一个EditText,我的问题是当PopupWindow可见时我点击了EditText那时软键盘不可见,我无法进入输入。有谁能告诉我如何解决这个问题?

4 个答案:

答案 0 :(得分:15)

当你创建一个新的PopupWindow时,使用另一个构造函数方法,你必须设置focusable = true;只有视图可以聚焦,软键盘才会显示。

public PopupWindow(View contentView, int width, int height, boolean focusable) {}

默认焦点是'false'

答案 1 :(得分:5)

有点想弄清楚,但是你走了:

创建弹出窗口时,我必须设置文本框(Edittext)以在接收焦点时强制打开软键盘。

 txtBox.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == true){
                InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                inputMgr.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);

            }
        }
    });
    txtBox.requestFocus();

答案 2 :(得分:4)

添加此代码 的 popupWindow.setFocusable(真);

答案 3 :(得分:1)

这对我有用。

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus && editText.isEnabled() && editText.isFocusable()) {
                editText.post(new Runnable() {
                    @Override
                    public void run() {
                        final InputMethodManager imm =(InputMethodManager)getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT);
                    }
                });
            }
        }
    });