2

My popup window should be auto dismissed when click outside. I already read this topic, and have set background drawable to the window. Here is my code:

    protected int showPopupWindow(final int popupWidth) {

        hideCalendarCellPopupWindow();

        final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
        final View popupView = inflater.inflate(R.layout.popup_calendar_cell, null);

        mCalendarCellPopupWindow = new PopupWindow(popupView, popupWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
        mCalendarCellPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        mCalendarCellPopupWindow.setOutsideTouchable(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCalendarCellPopupWindow.setElevation(...);
        }

        mCalendarCellPopupWindow.showAtLocation(....);
    }

    private hideCalendarCellPopupWindow() {
        if (mCalendarCellPopupWindow != null) {
            mCalendarCellPopupWindow.dismiss();
            mCalendarCellPopupWindow = null;
        }
    }

A problem have appeared on Android 10, as you can touch outside of the phone screen and slide the finger inside the screen, meanwhile "recent apps" could be shown with such gesture.

So my issue is when I slide the finger from the bottom to the top a little bit and than go back to the bottom - popup window is not dismissed, moreover it cannot be dissmissed no more, as its property isShowing() returns false. I have tried to call popupWindow.dismiss() method inside onPause() but it is not called as well in such situation.
This screencast could explain the issue more precies: https://youtu.be/w2cQMvFMYkk

What could be the workaround?

Oleksandr Albul
  • 1,611
  • 1
  • 23
  • 31

1 Answers1

0

If you want to dismiss your popup outside, you may set as following:

popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setOutsideTouchable(true);
popupWindow.update();
dingpwen
  • 161
  • 6