Android:在所有应用程序窗口上方但通知栏下方放置不可点击的视图 [英] Android : Place non-clickable view above all application windows but below notification bar

查看:239
本文介绍了Android:在所有应用程序窗口上方但通知栏下方放置不可点击的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,标题太长.我基本上想将SurfaceView添加为一个窗口,该窗口出现在所有窗口上方,但不在通知栏上方(即使向下拖动时).我目前拥有的代码是:

Sorry for the long title. I would basically like to add a SurfaceView as a window that appears above all windows but not above the notification bar (even when dragged down). The code I currently have is:

WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);

除了将视图放置在通知栏上方之外,这非常有效.如果改用TYPE_SYSTEM_ALERT,则可以实现所需的Z顺序,但是我的应用程序将不会响应用户输入.然后,我添加了标志FLAG_NOT_TOUCHABLE,该标志随后允许用户根据需要与应用程序组件进行交互.但是,电话上的后退"按钮和任务管理器按钮没有响应.

This works perfectly except it places the view above the notification bar. If I instead use TYPE_SYSTEM_ALERT, I can achieve the desired Z-order, but then my application will not respond to user input. I then added flag FLAG_NOT_TOUCHABLE, which then allows the user to interact with application components as desired. However, then the back button and the task manager button on the phone do not respond.

反正有实现我想要的行为的方法吗?我希望我已经说得足够清楚了,用语言很难形容我想要的东西.谢谢!

Is there anyway to achieve the behavior I'm looking for? I hope I made it clear enough, it's a bit difficult to describe in words what I would like. Thanks!

推荐答案

已解决!

WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
                        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
                        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                PixelFormat.TRANSLUCENT);

TYPE_SYSTEM_ALERT确保系统通知栏保持在我的视图上方. FLAG_NOT_TOUCH_MODAL允许将触摸事件发送到视图后面的窗口;和FLAG_NOT_TOUCHABLEFLAG_NOT_FOCUSABLE确保该视图不接收触摸或按键事件.

TYPE_SYSTEM_ALERT ensures that the system notification bar remains above my view. FLAG_NOT_TOUCH_MODAL allows touch events to be sent to the windows behind the view; and FLAG_NOT_TOUCHABLE and FLAG_NOT_FOCUSABLE ensure the view doesn't receive touch or key events.

这篇关于Android:在所有应用程序窗口上方但通知栏下方放置不可点击的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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