【问题标题】:PopupWindow overlaps Navigation DrawerPopupWindow 与 Navigation Drawer 重叠
【发布时间】:2020-01-16 14:04:24
【问题描述】:

目前我的弹出窗口与其他视图重叠。 setElevation(0) 没有任何改变。 setOverlapAnchor(false)setAttachedInDecor(true) 也没有多大帮助。下面是我使用的代码。我需要弹出窗口位于导航抽屉下

  private fun showPopup(anchorView: View) {
        PopupWindow(
            LayoutInflater.from(activity).inflate(
                R.layout.popup_layout,
                null
            ),
            100,
            100,
            false
        )
       .apply {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view?.elevation = 0f
                    contentView.elevation = 0f
                    elevation = 0f
                }
                isTouchable = false
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
                    isAttachedInDecor = true
                }

                PopupWindowCompat.setOverlapAnchor(this, false)
                PopupWindowCompat.showAsDropDown(this, anchorView, 0, 0, Gravity.NO_GRAVITY)
            }
    }

【问题讨论】:

  • 你想要的输出是什么?
  • 我需要弹出窗口位于导航抽屉下

标签: android popup popupwindow


【解决方案1】:

PopupWindow 是一个窗口。您的抽屉式导航位于另一个具有自己的视图层次结构的窗口

是这样的:

-- 活动
---- 窗口1
------ 视图层次结构
--------导航抽屉
---- 窗口2
------ 弹出窗口

使用 PopupWindow 无法实现您想要的。

一种可能的解决方法是在打开和关闭导航时隐藏和显示弹出窗口。这是回调:

https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html#ondrawerstatechanged

或者您可以自己添加一个视图作为弹出窗口并注意定位和重力。

最后但同样重要的是,请查看这些库,因为它们可能包含您想要的内容。它们与视图一起使用,因此您可以按照自己的方式管理它。

https://github.com/sephiroth74/android-target-tooltip

https://github.com/tomergoldst/tooltips

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多