I am trying to create a button that is always on the screen.
- The button should be clickable and
anything directly under the button
should not be activated on a press.
- The activity or home screen running
behind the button should still work,
meaning the user should still be
able to interact with the home
screen or application.
- The soft key
buttons should still work: home,
back, menu, etc
The following code does #1 and #2 but the soft key buttons no longer work:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
Changing it to this disables the overlay from clicks but #2 and #3 work:
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
Finally in this example the overlay and what is directly behind it gets clicked:
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
How can I change this so that the overlay is clickable, whats directly under it is not clickable, and everything outside of the overlay works including the home buttons?
An example application that performs all of this is Super Manager.
UPDATE: I've found that the following allows the home button to be used, but still not the other buttons:
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…