美文网首页
导航栏遮挡 PopupWindow 内容

导航栏遮挡 PopupWindow 内容

作者: Jiun俊 | 来源:发表于2021-11-09 11:05 被阅读0次

    Android 11 PopupWindow 内容区域会被 导航栏 遮挡,可以利用 FLAG_LAYOUT_IN_SCREEN 的 Flag 进行校正,如下:

    private fun setLayoutInScreenEnabled(popup: PopupWindow) {
      // 修复安卓11导航栏遮挡问题
      if (Build.VERSION.SDK_INT > BUILD_VERSION_CODE_Q) {
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as? WindowManager
        var viewContent = popup.contentView
        while (viewContent != null && viewContent.layoutParams !is WindowManager.LayoutParams) {
          viewContent = viewContent.parent as? View
        }
        if (viewContent?.layoutParams is WindowManager.LayoutParams) {
          val params = viewContent.layoutParams as WindowManager.LayoutParams
          params.flags = params.flags or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
          wm?.updateViewLayout(viewContent, params)
        }
      }
    }
    

    相关文章

      网友评论

          本文标题:导航栏遮挡 PopupWindow 内容

          本文链接:https://www.haomeiwen.com/subject/ljymzltx.html