0

I saw an app that overlays whole screen including nav bar (or soft-key that has back, home, etc.) today. it's CF.Lumen(requires android 4.4+) by chainfire.

I just remembered this is NOT POSSIBLE on general approach and many SO answers told me. So I looked down smali codes from Lumens apk(sorry chainfire), found 0x7d6 as type specifier, which is TYPE_SYSTEM_OVERLAY. In general, this makes a view overlays on top of lock screen. It looks good however it won't overlays nav bar area. even on lock screen. I did replacing MATCH_PARENT to 9999 but it still won't overlays nav bar area.

I looked down the source code of Android, found interesting that has more types undocumented.

FIRST_SYSTEM_WINDOW = 2000;

TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;

TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;

I applied these to my app but got crashe says permission denied. It requires INTERNAL_SYSTEM_WINDOW OR something more undocumented than SYSTEM_ALERT_WINDOW. those permissions are granted for system apps only.

here's my code to add a view fills whole screen except nav bar area.

What should I do to acomplish it?(make overlay including nav bar area)

final WindowManager.LayoutParams paramsRL = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
            PixelFormat.TRANSLUCENT);
windowManager.addView(view_floating, paramsRL);
Community
  • 1
  • 1
LaruYan
  • 51
  • 1
  • 6

2 Answers2

2

Here's a small example which works:

    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(Color.BLACK);
    frameLayout.setAlpha(0.5f);

    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
                    | WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            PixelFormat.TRANSLUCENT);

    //make sure height includes the nav bar size (get the dimension of whole screen)
    params.height = screenHeight;
    params.width = screenWidth;
    windowManager.addView(frameLayout, params);

    //add your view to this frameLayout
    frameLayout.addView(....);

Three key things here are:

  1. TYPE_SYSTEM_OVERLAY (or any similar types) which can show content over the whole screen.

  2. FLAG_LAYOUT_NO_LIMITS which allows us to go over the normal size allowed.

  3. Setting the extra height required to be covered behind soft keys. The main problem was when we set the parameters to match_parent, it sets to the height of screen minus the nav bar I suppose. Setting the extra height solves the issue.

Nishant Singh
  • 645
  • 7
  • 16
0

Don not use WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, this flag will make navigation bar always show. I don't kown why.

  • Good answers should have full explanations. Do some exploration, find out why your solution works. When you do share that information here. Try to think of Stack Overflow more of a community driven library of tech problems/solutions and less as a chat forum for people looking for a quick solution to a bug they can't fix. – Lenna Nov 19 '20 at 22:52