Read now

How to show screen overlay in Android

What is Screen Overlay?

Screen Overlay is a feature of the Android operating system that allows the applications to draw some layouts over the other applications. The most seen example of this feature is Facebook Messanger. Whenever you receive a message the chat head appears over any application and the user can easily see that whose message it is and can directly reply to it. The feature is supported by Android 23 and above.

Permissions Needed

Obviously, when your application starts to draw over other application’s UI then it is really going to interrupt the user while surfing the other application. Your application needs special permission from the user to do so. You must have seen the popup when you started using Facebook Messanger. You can see the screenshot below to the get the idea of the layout that appears when an app requests for permission.

If you also want your application to request this to a user then the below-provided code snippet will help you with that.

After this request, if the user permits your application then you will be able to draw over other apps.

How to draw Screen Overlay

1) First of all, Create a LayoutParams variable to define the overlay type, width, height, flags, etc.

2)Now we need a layout that will be inflated on the device window. Suppose we have a layout test.xml which looks something like.

and get the view that needs to be inflated

3) And now, you need to add this view on the screen using the WindowManager class.

How to remove Screen Overlay

To remove the screen overlay, you need to use the remove function of the same WindowManager class


You can play with the layouts and overlay types to get different results.

That’s all for this blog. Thank you very much. This is Vedesh Kumar signing off.

. . .

Comments (2)

Add Your Comment

  • James Edwards
    What do you put in the manifest
    • Vedesh Kumar
      Inside my application tag, I have added the broadcast receivers and admin permission.

  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again