【Android】修复部分系统拖拽窗口导致弹窗消失的问题

问题

PopupWindow内部对外部事件进行了过滤,如果触发外部事件,会自动关闭弹窗

有些处理得不够好的系统,拖拽边缘时会被误认为是Outside事件来处理,这样就导致了弹窗关闭

方法

对TouchEvent进行拦截,过滤混淆事件

代码
kotlin 复制代码
    override fun setContentView(view: View) {
        super.setContentView(view)
        interceptOutsideEvent()
    }

    @SuppressLint("ClickableViewAccessibility")
    private fun interceptOutsideEvent() {
        setTouchInterceptor { v, e ->
            val decorView = contentView.rootView
            if ((e.action == MotionEvent.ACTION_DOWN)) {
                val outside = e.x < 0 || e.x >= decorView.measuredWidth || e.y < 0 || e.y >= decorView.measuredHeight
                if (outside) {
                    ToastUtils.show("outside")
                    return@setTouchInterceptor true
                }
            } else if (e.action == MotionEvent.ACTION_OUTSIDE) {
                ToastUtils.show("outside")
                return@setTouchInterceptor true
            }
            return@setTouchInterceptor false
        }
    }
相关推荐
白云LDC8 小时前
Android Studio新建Vecter asset一直显示Loading icons(转圈圈)的解决办法
android·ide·android studio
Rytter11 小时前
某气骑士 libtprt.so 反 Frida 机制分析与绕过
android·安全·网络安全
alexhilton12 小时前
揭密:Compose应用如何做到启动提升34%
android·kotlin·android jetpack
沐言人生13 小时前
React Native 源码分析1——HybridData 机制深度分析
android·react native
程序员陆业聪14 小时前
跨平台框架全景图:Flutter/KMP/KuiKly/RN的2026年格局
android
码云数智-园园15 小时前
Fibers(纤程)来了:打破阻塞,实现纯PHP下的异步非阻塞IO
android
shaoming377618 小时前
检查系统硬件配置是否满足PyCharm最低要求
android·spring boot·mysql
一起搞IT吧18 小时前
高通Camx功能feature分析之十五:insensor zoom介绍及实现
android·智能手机·相机
aqi0019 小时前
一文读懂 HarmonyOS 6.1 带来的十大重要升级
android·华为·harmonyos·鸿蒙·harmony
秋921 小时前
MySQL 9.7.0 使用详解:新特性、实战与避坑指南
android·数据库·mysql