使用WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY将视图添加到窗口时,没有发生触摸事件 [英] When adding view to window with WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, it is not getting touch event

查看:695
本文介绍了使用WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY将视图添加到窗口时,没有发生触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在拨号器应用程序顶部显示我的视图,因此我为此使用TYPE_PHONE,这是可触摸的,但是在某些设备(例如Nexus 5拨号器应用程序)上,该设备仍将其隐藏.

I need to display my view on top of dialer application, so I was using TYPE_PHONE for this purpose which is touchable, but still on some devices like Nexus 5 dialer application of device is hiding it.

尝试使用TYPE_SYSTEM_OVERLAY使视图在拨号程序应用程序顶部可见,但触摸不存在.任何与此有关的帮助都将很棒.

Tried using TYPE_SYSTEM_OVERLAY makes view visible on top of dialer application, but touch is not there. Any help regarding this will be great.

推荐答案

在对上述问题进行了大量搜索之后,我找到了解决方案.这就是我使视图位于设备内部所有内容之上并使其可触摸的方式,而使用TYPE_SYSTEM_OVERLAY则无法实现.

After lot of searching for above problem, I found solution my self. Here it is how I made view to be on top of everything inside device and also making it touchable which was not possible with TYPE_SYSTEM_OVERLAY.

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                        WindowManager.LayoutParams.MATCH_PARENT,
                        WindowManager.LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                        PixelFormat.TRANSPARENT);

params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(view, params);

这篇关于使用WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY将视图添加到窗口时,没有发生触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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