如何在 PopupWindow 上显示键盘?

发布于 2024-09-27 02:49:40 字数 187 浏览 1 评论 0原文

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

I am using PopupWindow class and on PopupWindow I have one EditText, my problem is that when PopupWindow is visible and I click on EditText at that time the soft keyboard is not visible and I am not able to enter Input. Can anybody tell me how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仲春光 2024-10-04 02:49:40

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

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

默认可聚焦为“false”

When you create a new PopupWindow, use another constructor method, you must set the focusable = true; only the view could be focusable, the soft keyboard will show .

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

The Default focusable is 'false'

短叹 2024-10-04 02:49:40

花了相当多的时间才弄清楚,但是在这里:

在创建弹出窗口时,我必须设置文本框(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();

Took quite a bit to figure out, but here you go:

While creating the popup, I had to set the textbox (Edittext) to force opening the soft keyboard when receiving focus.

 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();
驱逐舰岛风号 2024-10-04 02:49:40

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

Add this code
popupWindow.setFocusable(true);

半步萧音过轻尘 2024-10-04 02:49:40

这对我有用。

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);
                    }
                });
            }
        }
    });

This worked for me.

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);
                    }
                });
            }
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文