打开PopupWindow,让外侧仍然可触摸 [英] Open a PopupWindow and let the outsides still touchable

查看:482
本文介绍了打开PopupWindow,让外侧仍然可触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开Android上PopupWindow,让所有其他部件可触及不驳回PopupWindow?

这是它是如何创建的:

 公共类DynamicPopup {
    私人最终PopupWindow窗口;
    私人最终RectF RECT;
    私人最终查看父母;
    私人最终RichPageView图。    公共DynamicPopup(上下文的背景下,RichPage页,RectF rectF,查看父){
        this.parent =父母;
        RECT = rectF;        窗口=新PopupWindow(上下文);        window.setBackgroundDrawable(新BitmapDrawable());
        window.setWidth((int)的rect.width());
        window.setHeight((int)的rect.height());
        window.setTouchable(真);
        window.setFocusable(真);
        window.setOutsideTouchable(真);        鉴于=新RichPageView(背景下,页面,假);
        window.setContentView(视图);        view.setOnCloseListener(新侦听器(){
            @覆盖
            公共无效的OnAction(){
                window.dismiss();
            }
        });
    }    公共无效显示(){
        window.showAtLocation(父母,Gravity.NO_GRAVITY,(INT)rect.left,(INT)rect.top);
    }
}


解决方案

根据的javadoc


  

控制是否弹出将触摸事件的其窗口之外被告知。这仅是有道理的弹出窗口是可触摸的,但不可作为焦点


所以你的行

  window.setFocusable(真);

则此方法 setOutsideTouchable()什么都不做。

How to open a PopupWindow on Android and let all the others components touchable without dismiss the PopupWindow?

This is how it's created:

public class DynamicPopup {
    private final PopupWindow window;
    private final RectF rect;
    private final View parent;
    private final RichPageView view;

    public DynamicPopup(Context context, RichPage page, RectF rectF, View parent) {
        this.parent = parent;
        rect = rectF;

        window = new PopupWindow(context);

        window.setBackgroundDrawable(new BitmapDrawable());
        window.setWidth((int) rect.width());
        window.setHeight((int) rect.height());
        window.setTouchable(true);
        window.setFocusable(true);
        window.setOutsideTouchable(true);

        view = new RichPageView(context, page, false);
        window.setContentView(view);

        view.setOnCloseListener(new Listener(){
            @Override
            public void onAction() {
                window.dismiss();
            }
        });


    }

    public void show() {
        window.showAtLocation(parent, Gravity.NO_GRAVITY, (int) rect.left, (int) rect.top);
    }
}

解决方案

As per javadocs

Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable

So your line

 window.setFocusable(true);

causes the method setOutsideTouchable() to do nothing.

这篇关于打开PopupWindow,让外侧仍然可触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆