【问题标题】:PopUpWindow ignores fullscreen and also the CutoutModePopUpWindow 忽略全屏和 CutoutMode
【发布时间】:2021-09-16 22:23:03
【问题描述】:

我的应用是全屏应用。它全宽并且不显示状态栏,使用 CutoutMode 并隐藏控件,如(Home 和 Back)。这也很有效。

但是,当我创建 PopUpWindow 时,这些设置似乎没有生效。见下图:

我原以为左右两边用红色标记的四边形也会处于相应的灰色阴影中。

我初始化弹出窗口的代码如下所示:

 val inflater =
        view.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater
            ?: return

    // Inflate a custom view using layout inflater
    val popUpView = inflater.inflate(R.layout.view_change_name, null)

    //popUpView.animation = AnimationUtils.loadAnimation(view.context, R.anim.fade_in_animation)
    // Initialize a new instance of popup window
    val popupWindow = PopupWindow(
        popUpView, // Custom view to show in popup window
        LinearLayout.LayoutParams.MATCH_PARENT, // Width of popup window
        LinearLayout.LayoutParams.MATCH_PARENT, // Window height
        true
    )
    popupWindow.animationStyle = R.style.PopUpWindowAnimation
    popupWindow.isFocusable = true
    popupWindow.isOutsideTouchable = true
    popupWindow.update(
        0,
        0,
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.MATCH_PARENT
    )

    //Set the location of the window on the screen
    popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0)

我在我的活动中获得全屏的方法是这样的。

fun Activity.fullscreen() {
    with(WindowInsetsControllerCompat(window, window.decorView)) {
        systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE
        hide(Type.systemBars())
    }
}

所以我的想法是在 PopUpWindow 中获得一个 decorView。但我认为 PopUpWindow 没有 decorView。我的想法不多了。有没有人有办法或解决方案?

【问题讨论】:

    标签: android kotlin android-popupwindow android-fullscreen


    【解决方案1】:

    多么愚蠢。发布此问题后,我找到了答案。

    使用

    popupWindow.isClippingEnabled = false
    

    文档

    @param enabled false if the window should be allowed to extend outside of the screen
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-12
      • 2016-04-13
      • 1970-01-01
      • 2015-04-17
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多