【问题标题】:Popup window dismissal弹出窗口解除
【发布时间】:2013-08-06 18:36:07
【问题描述】:

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

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();
    }

【问题讨论】:

标签: android android-layout


【解决方案1】:

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

希望对你有帮助。

【讨论】:

  • 不,它仍然无法正常工作,我已经编辑了我的代码,显示了解除方法。@giga_abhi
  • 我需要将焦点设置为 true,因为我有按钮并在弹出窗口中编辑文本
  • 在关闭它之前尝试输入pwindo.setBackgroundDrawable(new BitmapDrawable(getResources()));!它对我有用。
【解决方案2】:

终于解决了!更改顺序:

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);

现在可以了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多