当其 mFocusable 设置为 false 时,如何通过触摸关闭 PopupWindow?

How to dismiss PopupWindow with touch outside when its mFocusable set false?

我有一个 PopupWindow,它是 setFocusable(false),我想在触摸外部时关闭它,它已经是 setOutsideTouchable(true),但是有了 setFocusable(false)不起作用,我该如何解决?提前致谢。

为我的 PopupWindow 设置的所有属性如下:

popUpWindow.setBackgroundDrawable(xx);
popUpWindow.setTouchable(true);
popUpWindow.setFocusable(false);
popUpWindow.setOutsideTouchable(true);
popUpWindow.setAnimationStyle(android.R.style.Animation_Dialog);
popUpWindow.update();

更新:

我错了,PopupWindow 被忽略了,但其他一些代码让它显示出来。

可能有用

// Removes default background.
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
myPopupWindow.setOutsideTouchable(true);

或者:

myPopupWindow.setFocusable(true);

不确定有什么区别,但 ListPopupWindow 源代码实际上使用后者,当它的模态通过 setModal 设置为 true 时,所以至少 Android 开发人员认为这是一种可行的方法,而且它只是一行。

顺便说一句,不要使用 BitmapDrawable 已弃用的构造函数,请使用此 new ColorDrawable(android.R.color.transparent) 替换默认背景。

快乐编码:)