PopupWindow - 在外面点击时关闭 [英] PopupWindow - Dismiss when clicked outside

查看:57
本文介绍了PopupWindow - 在外面点击时关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动中有一个 PopupWindow,问题是即使我正在与我的活动进行交互(比如在我的列表上滚动),我的 PopupWindow 仍然显示.我可以滚动我的列表,而 PopupWindow 仍然存在.

I have a PopupWindow on my activity, the thing is my PopupWindow still shows even when I'm interacting with my activity (say scrolling on my list). I can scroll through my list and the PopupWindow is still there.

我想要实现的是当我在不是 PopupWindow 的屏幕上触摸/滚动/点击/等时,我想关闭 PopupWindow.就像菜单的工作原理一样.如果您在菜单外单击,菜单将被关闭.

What I want to achieve is when I'm touching/scrolling/clicking/etc on the screen which is not the PopupWindow, I want to dismiss the PopupWindow. Just like how a menu works. If you clicked outside of the menu, the menu will be dismissed.

我试过 setOutsideTouchable(true) 但它不会关闭窗口.谢谢.

I've tried setOutsideTouchable(true) but it won't dismiss the window. Thanks.

推荐答案

请尝试将 setBackgroundDrawable 设置在 PopupWindow 上,如果您触摸它的外部,它应该关闭窗口.

Please try to set setBackgroundDrawable on PopupWindow that should close the window if you touch outside of it.

这篇关于PopupWindow - 在外面点击时关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆