Android 如何在弹出窗口上显示键盘?
我正在使用Android 如何在弹出窗口上显示键盘?,android,android-softkeyboard,popupwindow,Android,Android Softkeyboard,Popupwindow,我正在使用PopupWindow类,在PopupWindow上我有一个EditText,我的问题是当PopupWindow可见时,我点击EditText时,软键盘不可见,我无法输入。有谁能告诉我如何解决这个问题吗?花了不少时间才弄明白,但现在您可以开始: 在创建弹出窗口时,我必须设置文本框(Edittext),以便在接收焦点时强制打开软键盘 txtBox.setOnFocusChangeListener(new OnFocusChangeListener() { public
PopupWindow
类,在PopupWindow
上我有一个EditText
,我的问题是当PopupWindow
可见时,我点击EditText
时,软键盘不可见,我无法输入。有谁能告诉我如何解决这个问题吗?花了不少时间才弄明白,但现在您可以开始:
在创建弹出窗口时,我必须设置文本框(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();
创建新的
PopupWindow
时,使用另一个构造函数方法,必须将focusable=true代码>只有视图可以聚焦,软键盘将显示
public PopupWindow(View contentView, int width, int height, boolean focusable) {}
默认聚焦为“false”添加此代码
popupWindow.setFocusable(真)这对我很有效
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);
}
});
}
}
});
谢谢,我错过了那个在我的案子里工作的人。尝试使用popupWindow.update()
,但对我无效。