【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
        }
    }
相关推荐
有位神秘人3 小时前
Android中PopupWindow中如何弹出时让背景变暗
android
TheNextByte14 小时前
iPhone 与Android :有什么区别?
android·cocoa·iphone
_李小白4 小时前
【Android 美颜相机】第二十一天:GPUImageChromaKeyBlendFilter (颜色加深混合滤镜)
android·数码相机
yantaohk5 小时前
【2025亲测】中兴B860AV3.2M完美刷机包ATV版本安卓9-解决1G运存BUG,开ADB已ROOT
android·嵌入式硬件·adb·云计算
乐观勇敢坚强的老彭6 小时前
c++信奥寒假营集训01
android·java·c++
kdniao16 小时前
PHP 页面中如何实现根据快递单号查询物流轨迹?对接快递鸟在途监控 API 实操
android·开发语言·php
言之。6 小时前
MacBook M3 Pro:React Native 安卓开发
android·react native·react.js
感觉不怎么会6 小时前
Android 13 - 对讲app后台休眠后无法录音
android·linux
Minilinux20187 小时前
Android系列之 屏幕触控机制(一)
android·屏幕触控·andorid touch·viewroot
冰语竹7 小时前
Android学习-随笔(安装后设置路径)
android·学习