【问题标题】:Popup window auto dismiss on Android 10Android 10 上的弹出窗口自动关闭
【发布时间】:2020-06-25 06:02:20
【问题描述】:

点击外部时,我的弹出窗口应该会自动关闭。我已经阅读了this topic,并为窗口设置了可绘制的背景。这是我的代码:

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

Android 10出现了一个问题,你可以在手机屏幕外触摸并在屏幕内滑动手指,同时这种手势会显示“最近的应用程序”。

所以我的问题是当我将手指从底部滑动到顶部一点点然后返回底部时 - 弹出窗口不会被关闭,而且它不能再被关闭,因为它的属性 isShowing() 返回错误的。我曾尝试在onPause() 中调用popupWindow.dismiss() 方法,但在这种情况下也不会调用它。
这个截屏视频可以更详细地解释这个问题:https://youtu.be/w2cQMvFMYkk

有什么解决方法?

【问题讨论】:

    标签: android gesture popupwindow dismiss


    【解决方案1】:

    如果你想在外面关闭你的弹窗,你可以设置如下:

    popupWindow.setFocusable(true);
    popupWindow.setTouchable(true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    popupWindow.setOutsideTouchable(true);
    popupWindow.update();
    

    【讨论】:

    • 它也不起作用。有时我可以实现冻结弹出窗口,无法关闭。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    相关资源
    最近更新 更多