Android之解决点击PopupWindow外部不消失并且不穿透事件

本文介绍了在Android中如何解决PopupWindow在外部点击时不消失且不穿透事件的问题。通过设置PopupWindow的mFocusable和mOutsideTouchable属性,以及分析事件分发机制,最终通过重写Activity的dispatchTouchEvent方法来阻止外部事件传递,实现了所需效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 问题

需要实现PopupWindow内部可以点击,但是外部点击不会消失

 

 

 

 

 

2 初步解决办法

设置PopupWindow的mFocusable属性mOutsideTouchable属性,我们知道如果我们不想穿透事件,也就是说,不想出现点击Popuowindow外部的文本框或者按钮生效,我们需要获取Popuowindow的焦点,也就是设置mFocusable值为true

也就是setFocusable( true ),然后我们分析mOutsideTouchable的设置函数解释

    /**
     * <p>Controls whether the pop-up will be informed of touch events outside
     * of its window.  This only makes sense for pop-ups that are touchable
     * but not focusable, which means touches outside of the window will
     * be delivered to the window behind.  The default is false.</p>
     *
     * <p>If th
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码莎拉蒂 .

你的鼓励是我最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值