I am creating an Android App in which I am showing a floating view on top of all apps by using a service and Window Manager. I am trying to add WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES in my Window Manager params to enable my layout to overlay with display cutouts. But it seems like this is not working in my case.
I have already tried to add it in both ways:
By using XML styling:
<style name="OverlayTheme"> <item name="android:windowLayoutInDisplayCutoutMode"> shortEdges <!-- default, shortEdges, never --> </item> </style>
And added this style in my layout root view. But it does not work.
By using the JAVA code in my service:
params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
It also not working. I am not sure if I am applying the Layout Params Correctly or not. Please help me to figure out the problem. Thanks in advance.
Edit:
This is the way I had implemented my the bubble in my service:
Initialized Window Manager and Layout in onCreate() method:
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (inflater != null) mLayout = inflater.inflate(R.layout.my_layout, null, false);
Added this view to window by Window Manager:
WindowManager.LayoutParams params; params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
Finally added this view to Window by addView Method:
windowManager.addView(mLayout, params);
By using the above methods I am able to show my view on top of other apps. But the problem is that my view is not not overlapping with a display cutout. This is happening when android is in landscape mode.
Solution:
I solved this by just adding this line of code (As suggested in Answere):
params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
Try setting in your
Activity
: