【发布时间】: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