1

我动态创建的包含 EditText 的 PopupWindow 具有以下属性:

popup.setTouchable(true);  
popup.setFocusable(false); 

强制键盘显示:

InputMethodManager inputMgr = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
inputMgr.showSoftInput(root, InputMethodManager.SHOW_IMPLICIT);

显示键盘,但没有从键盘接收任何输入(即按下键不会将文本添加到文本编辑器)并且选择了文本编辑器,因为我可以看到光标闪烁。

我将 setFocusable 设置为 false,因为我不希望 PopupWindow 在我单击它外部时关闭。我怎样才能让键盘工作?

4

2 回答 2

2

您可以使用这些PopupWindow方法完成所有操作。

  1. 您不需要InputMethodManager强制显示软键盘。

    // Shows soft keyboard if it is not already visible.
    popup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    
  2. 然后,您需要允许键盘交互。

    // Allows interaction with the soft keyboard.
    popup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    
  3. 此外,您无需更改可聚焦性即可更改外部触摸行为。

    // PopupWindow ignores outside touches.
    popup.setOutsideTouchable(false);
    
于 2012-10-24T04:11:03.057 回答
0

我怀疑如果您将 setFocusable 设置为 false,那么发生的情况是键盘已启动,因为您将其强制启动,但它实际上并没有与该字段交谈。您应该使您的弹出字段成为一个主题为 Dialog... 的活动,这将产生相同的效果,并且您不需要弄乱焦点。

于 2012-06-08T23:17:56.097 回答