Android : Place non-clickable view above all application windows but below notification bar
Asked Answered
R

1

0

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);

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!

Rehearing answered 24/5, 2016 at 16:56 Comment(0)
R
2

Solved!

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 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.

Rehearing answered 19/7, 2016 at 20:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.