当外部点击时,如何使用和关闭PopupWindow? [英] How to consume and dismiss the PopupWindow when clicked outside?

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

问题描述

我目前正在使用 PopupWindow 课程设计简单的提示弹出式窗口。我可以在内容之外点击时关闭弹出窗口。然而,外部的触摸事件是由下划线布局消耗的。如何消除外面的触摸,以便在外部点击时,我仍然有弹出窗口被关闭,但没有触摸事件发送到我的 PopupWindow

I'm currently designing simple tips popups using the PopupWindow class. I'm able to dismiss the popup when clicked outside of the content. However the touch events outside are consumed by the underlining layout. How can I consume the outside touches so that when clicked outside I still have the popup dismissed but there are no touch events being sent to the layout below my PopupWindow?

当前设置属性:

Current set properties:

mPopupWindow.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.popup_bg));
mPopupWindow.setOutsideTouchable(true);


推荐答案

原来有办法做到!在深入PopupWindow和ListPopupWindow之后,我发现选项 setFocusable(true); 将完全符合我的需要!

Turns out there is a way to do it! After looking deep into PopupWindow and ListPopupWindow I discovered the option setFocusable(true); will do exactly what I needed!

这篇关于当外部点击时,如何使用和关闭PopupWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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