1

我希望能得到这个答案,当我点击外面时,我已经非常努力地关闭弹出窗口,但它没有关闭,有人知道为什么吗?当我单击返回按钮时,它也不会返回。

public void onButtonPopup (View target) {
       // Make a View from our XML file
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y; 

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.samplescreens, (ViewGroup) findViewById(R.id.closeLayout));


        pwindo = new PopupWindow(layout, width-40, height-(height/4), true);
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

        pwindo.update();
        pwindo.setOutsideTouchable(true);
    }
public void onButtonInPopup (View target) {
        //back_dim_layout.setVisibility(View.GONE);
        pwindo.dismiss();
    }
4

2 回答 2

0

终于解决了!改变了顺序:

pwindo = new PopupWindow(layout, width-40, height-(height/4), true);

        pwindo.setOutsideTouchable(true);
        pwindo.setTouchable(true);
        pwindo.setBackgroundDrawable(new BitmapDrawable());
        pwindo.setTouchInterceptor(customPopUpTouchListenr);

    pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

现在可以了

于 2013-08-07T13:40:41.580 回答
0

您的代码中的一个问题是您已经编写pwindo = new PopupWindow(layout, width-40, height-(height/4), true);了第四个参数,true即保持弹出窗口可聚焦。这是错误的,就好像你说pwindo.setOutsideTouchable(true);你已经定义了弹出窗口应该是可聚焦的。将第四个参数设为false. 不过,如果您无法关闭它,那么在关闭弹出窗口之前,请pwindo.dismiss()写下这一行,pwindo.setBackgroundDrawable(new BitmapDrawable(getResources()));.

希望它可以帮助你。

于 2013-08-07T05:09:15.090 回答