【发布时间】:2021-05-08 10:15:23
【问题描述】:
我正在使用窗口服务在屏幕上绘制叠加层。但是我的覆盖没有覆盖整个屏幕,它没有显示状态栏和导航栏。 我尝试了不同的方法来解决它,但没有找到任何解决方案。但是解决方案是可用的,因为 Play Store 上的某些应用程序(边缘照明)在全屏上绘制边框(即使在 Android O 上也是如此)。
我的代码sn-p来完成任务。
-
窗口管理器
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) { 超级.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)}`
【问题讨论】:
标签: android android-windowmanager