4

我正在使用PopupWindow类并且PopupWindow我有一个EditText,我的问题是什么时候PopupWindow可见并且我点击EditText当时软键盘不可见并且我无法输入输入。谁能告诉我如何解决这个问题?

4

4 回答 4

15

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

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

默认可聚焦为“假”

于 2011-12-14T15:37:02.177 回答
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();
于 2011-04-08T14:44:14.670 回答
4

添加此代码 popupWindow.setFocusable(true);

于 2012-03-06T09:22:52.753 回答
2

这对我有用。

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);
                    }
                });
            }
        }
    });
于 2017-11-01T00:38:44.290 回答