我正在使用PopupWindow
类,PopupWindow
上有一个EditText
,我的问题是当PopupWindow
可见时,我点击EditText
时软键盘不可见,因此我无法输入。请问有人能告诉我如何解决这个问题吗?
我正在使用PopupWindow
类,PopupWindow
上有一个EditText
,我的问题是当PopupWindow
可见时,我点击EditText
时软键盘不可见,因此我无法输入。请问有人能告诉我如何解决这个问题吗?
创建新的PopupWindow
时,使用另一个构造方法,你必须设置focusable = true;
只有视图可聚焦时,软键盘才会显示。
public PopupWindow(View contentView, int width, int height, boolean focusable) {}
默认focusable为'false'
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();
Add this code popupWindow.setFocusable(true);
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()
,但对我来说没有起作用。 - esfox