Yehonatan

Android Display Overlay

Mar 21st, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // setTargetSDK = 19
  2.  
  3. WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
  4.  
  5. Button overlayedButton = new Button(this);
  6. overlayedButton.setText("Overlay button");
  7. overlayedButton.setOnTouchListener(this);
  8. overlayedButton.setAlpha(1);
  9. overlayedButton.setBackgroundColor(Color.BLACK);
  10. overlayedButton.setOnClickListener(this);
  11.  
  12. WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
  13. params.gravity = Gravity.LEFT | Gravity.TOP;
  14. params.x = 0;
  15. params.y = 0;
  16. wm.addView(overlayedButton, params);
  17.  
  18. View topLeftView = new View(this);
  19. WindowManager.LayoutParams topLeftParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
  20. topLeftParams.gravity = Gravity.LEFT | Gravity.TOP;
  21. topLeftParams.x = 0;
  22. topLeftParams.y = 0;
  23. topLeftParams.width = 0;
  24. topLeftParams.height = 0;
  25. wm.addView(topLeftView, topLeftParams);
Advertisement
Add Comment
Please, Sign In to add comment