我正在使用窗口服务在屏幕上绘制叠加层。但是我的叠加层没有覆盖整个屏幕,它遗漏了状态栏和导航栏。 我尝试了不同的方法来解决它,但没有找到任何解决方案。但解决方案是可用的,因为 Play 商店中的一些应用程序(边缘照明)在全屏上绘制边框(甚至在 Android O 上)。
我完成任务的代码片段。
窗口管理器
int Layout_Flag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Layout_Flag = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}else {
Layout_Flag = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
}
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
Layout_Flag,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER;
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(customView, params);
绘图边缘
`override fun onDraw(canvas: Canvas) { super.onDraw(画布) // 绘制形状 val 宽度 = 测量宽度 val 高度 = 测量高度
val strokeWidthCalculation = paint.strokeWidth / 2
path?.moveTo(strokeWidthCalculation, strokeWidthCalculation)
path?.lineTo(width - strokeWidthCalculation, strokeWidthCalculation)
path?.lineTo(width - strokeWidthCalculation, height - strokeWidthCalculation)
path?.lineTo(strokeWidthCalculation, height - strokeWidthCalculation)
path?.close()
paint.pathEffect = cornerPathEffect
canvas.drawPath(path!!, paint)
}`