【问题标题】:System Overlay not covering Status bar & Navigation bar Android系统覆盖不覆盖状态栏和导航栏 Android
【发布时间】:2021-05-08 10:15:23
【问题描述】:

我正在使用窗口服务在屏幕上绘制叠加层。但是我的覆盖没有覆盖整个屏幕,它没有显示状态栏和导航栏。 我尝试了不同的方法来解决它,但没有找到任何解决方案。但是解决方案是可用的,因为 Play Store 上的某些应用程序(边缘照明)在全屏上绘制边框(即使在 Android O 上也是如此)。

我的代码sn-p来完成任务。

  1. 窗口管理器

        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);
    
  2. 绘图边

    `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)
    

    }`

  3. 结果 sample image, not covering status and navigation bar

【问题讨论】:

    标签: android android-windowmanager


    【解决方案1】:

    为了实现它,WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS的第四个参数。

    就是这样。

    整个完整代码:

    val LAYOUT_FLAG: Int
        LAYOUT_FLAG = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
        } else {
            WindowManager.LayoutParams.TYPE_TOAST
        }
        params = WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            LAYOUT_FLAG,  // NOTE
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
            PixelFormat.TRANSLUCENT
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      相关资源
      最近更新 更多