Allahjane Allahjane - 10 months ago 46
Android Question

Android: How to draw free on top of anything (any activity)

How do you draw a view on top of all other activities regardless of what they are showing and without using transparent activities or consuming its touch events.

Its like to display a custom icon on the screen on top of all other apps that reacts when you touch it but you can still touch the other views on the screen.

Example: facebook chat heads that displays a dragable and clickable icon on screen regardless of what you are doing whether you are on home screen or app menus or any app. Still you can click the chat head icon and background app elements seperately

How to do anything like that?


Take a look at this cool article, I think that's exactly what you want :

In short : you want to add this permission to your manifest :

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

For api >= 23, you'll need to request the runtime permission Settings.ACTION_MANAGE_OVERLAY_PERMISSION

Then in a service, get the window manager

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

and add your views with the addView method