Drawing Edge Overlay on Android

Viewed 113

I try searching over the internet about screen overlay/draw over apps in android. I know that starting from Android O,

WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY

is deprecated.

I want to make overlay view like Muviz Edge. But I can't find how to draw under or over status bar like that app.

How Muviz app can do it without using

TYPE_SYSTEM_OVERLAY Flag.

Muviz Edge App Overlay

This is my Overlay, the left top red color text is behind status bar

1 Answers

I got my own answer after searching hours over the internet and testing around different possible flags of

WindowManager.LayoutParams

Flags I realized that I was searching in wrong direction.

In order to draw the whole screen, the fourth parameter of

WindowManger.LayoutParams

should be

 WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS

instead of other flags.

The complete code for Window manager Layout Param is

val LAYOUT_FLAG: Int
    LAYOUT_FLAG = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
    } else {
        WindowManager.LayoutParams.TYPE_TOAST
    }
    params = WindowManager.LayoutParams(
        WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.MATCH_PARENT,
        LAYOUT_FLAG,  
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
        PixelFormat.TRANSLUCENT
    )
Related