【问题标题】:Android Popup with EditText, keyboard blocks text, background scrolls带有 EditText、键盘块文本、背景滚动的 Android 弹出窗口
【发布时间】:2012-07-10 05:03:12
【问题描述】:

我有一个 Popup,它在 ScrollView 中保存了几个 EditText。 当我单击 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 的视图“启动”的。

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

【问题讨论】:

    标签: java android popup


    【解决方案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的行为。

    EDIT 为澄清起见,如果您需要访问在对话框的自定义布局中定义的视图,您可以像这样访问它:

    EditText e1 = (EditText) dialog.findViewById(R.id.e1);
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 2018-03-08
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 2013-02-22
      • 2022-06-15
      相关资源
      最近更新 更多