如何在PopupWindow上显示键盘?

use*_*366 4 android popupwindow android-softkeyboard

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

小智 14

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

public PopupWindow(View contentView, int width, int height, boolean focusable) {}
Run Code Online (Sandbox Code Playgroud)

默认焦点是'false'


Run*_*gen 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();
Run Code Online (Sandbox Code Playgroud)