Back in Android Marshmallow, Google introduced a feature that allowed apps to display on top of other apps. Things like Facebook Messenger and Twilight take advantage of this feature to be able to essentially run on-screen at the same time as other foreground applications.
RELATED: How to Fix the “Screen Overlay Detected” Error on Android