Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a PopupWindow and let the outsides still touchable

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);
    }
}
like image 274
Marcos Vasconcelos Avatar asked Sep 01 '11 14:09

Marcos Vasconcelos


1 Answers

just like the ernazm say

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

and it's work on

window.setTouchable(true);
window.setFocusable(false);
window.setOutsideTouchable(false);

When window touchalbe is true, focusable is false, setOutsideTouchable() is work, if setOutsideTouchable(true), touch outside of popupwindow will dismiss, otherwise the outside of popupwindows still can be touchable without dismiss.

like image 173
Jay Parker Avatar answered Sep 21 '22 11:09

Jay Parker