Search code examples
androidoverlayfullscreen

How to change Screen overlay after system ui mode changed(Fullscreen, hide navigation)?


I create overlay:

mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    /*The parent view (actually the root view) the will be added in front of all the windows on the screen*/
    mOverlayView = (RelativeLayout) inflater.inflate(R.layout.overlay_control, null);

        mWindowManager.getDefaultDisplay().getSize(size);
        mWindowSize = new Size(size.x, size.y);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
                    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.TOP | Gravity.LEFT;
    mWindowManager.addView(mOverlayView, params);

I need to move overlay if system UI Visibility changed. There is possibility to detect it(documentation) for view but it not works for overlay. So I only need callback to detect if mode of device changed.


Solution

  • I found the way to do it:

    In Android there is OnSystemUiVisibilityChangeListener but it not works if there is not view which will has match_parent value of width or hight.

    So I created such overlay and made it 1 px height and match_parent width and add OnSystemUiVisibilityChangeListener to it.