安卓弹出窗口带有EditText,键盘挡住了文本,背景滚动。

3

我有一个弹出窗口,里面有几个EditText在ScrollView中。当我点击EditText时,它会将背景视图向上滚动,而不是弹出窗口,因此键盘会挡住EditText。

有什么想法吗?

PopupWindow popUp = new PopupWindow(this);
popUp.update(0, 0, display.getWidth(), display.getHeight());
popUp.setFocusable(true);

LinearLayout llh = new LinearLayout(this)
llh.setOrientation(LinearLayout.HORIZONTAL);
ScrollView sv = new ScrollView(this);

EditText e1,e2,e3...
llh.addView(e1);    
llh.addView(e2);    
llh.addView(e3);
...
sv.addView(llh);
popUp.setContentView(llh);
popUp.showAtLocation(llh, Gravity.BOTTOM, 0, 0);

这是从一个包含ScrollView的View中“启动”的。

如果有解决方法,那就太好了。

1个回答

1
我曾经遇到过和你一样的问题,为了解决它,我创建了一个自定义的Dialog,并使用了自定义主题(在下面的示例中是R.style.ThemeDialogCustom)。我还设置了dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)dialog.setCanceledOnTouchOutside(true);,并使用setContentView设置了自定义布局。就像这样:
Dialog dialog = new Dialog(activityContext, R.style.ThemeDialogCustom);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(true); 
dialog.setContentView(R.layout.custom_dialog_layout);

换句话说,上述代码片段试图模仿PopupWindow的行为。 编辑 为了澄清,如果您需要访问在对话框的自定义布局中定义的视图,可以像这样访问它:
EditText e1 = (EditText) dialog.findViewById(R.id.e1);

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接