How to Overlay screen?
- it should be touchable
- view must overlay system action bar
- view must overlay soft buttons back/home/recent_apps
Android 4.0 +
public class MyService extends Service { @Override public void onCreate() { super.onCreate(); WindowManager.LayoutParams params = ViewUtils.generateFullScreenParams(true); final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(overlayView, params); } ... }
and layout params creator
public static WindowManager.LayoutParams generateFullScreenParams() { return new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT); } ok, looks good.
Flag TYPE_SYSTEM_ALERT not overlays the system bar (android < 5.0), not overlays soft buttons, but I can to handle onTouch event
Flag TYPE_SYSTEM_OVERLAY overlays the system bars, not overlays buttons and I can't to handle onTouch event.
Any ideas?
1 Answers
Answers 1
public static WindowManager.LayoutParams generateFullScreenParams() { return new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT); } in This Code You added WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE remove this line its works and add touch event on view its works
For The Screen Overlay permission I am Referring to this post How to enable screen overlay permission by default
0 comments:
Post a Comment