6

我有一个相对布局弹出窗口,它显示在按钮单击上。我在同一屏幕上有一些其他视图,弹出窗口覆盖了它们。但是当我点击弹出窗口时,后面的控件/视图被点击了。如何禁用此功能?

(我有一个解决方案是获得所有的意见和setClickable = false。)

但我正在寻找其他一些解决方案,比如将注意力集中在当前视图上,以便将其他视图设置为禁用。

4

4 回答 4

6

I had this same problem, and finally instead of setting everything behind as clickable=false, I simply added clickable=true to the popup layout and it fixed it. The clickable views behind the popup no longer respond to click events through the popup. :) And I didn't even have to change my popup into a dialog. :)

于 2014-06-16T18:23:24.327 回答
2

将 setOnClickListener() 激活到 RelativeLayout 对象。这会捕获所有点击并防止背后的控件/视图被点击。

例如:-

    RelativeLayout rObj = (RelativeLayout) findViewById(R.id.yourRelativeLayout);
    rObj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // filter touches when underlying view is Obscured by this view.
        }
    });
于 2012-10-13T09:39:38.967 回答
2

使用对话框。我认为这是弹出要求的最佳解决方案。

final Dialog dialog = new Dialog(NewEntryActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.interview_tab6_popup_drink_containg_alcohol);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
于 2012-11-24T12:57:58.210 回答
1

为此,您RelativeLayout可以BringToFront()

并提出其他意见SetEnabled(false)

于 2012-10-13T06:53:36.747 回答