【发布时间】: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