Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PopupWindow with dim background
val popup = PopupWindow(...)
val container = popup.contentView.takeIf { it.layoutParams is WindowManager.LayoutParams }
?: (popup.contentView.parent as? View)?.takeIf { it.layoutParams is WindowManager.LayoutParams }
?: (popup.contentView.parent.parent as? View)?.takeIf { it.layoutParams is WindowManager.LayoutParams }
?: throw IllegalStateException("NO WindowManager.LayoutParams!")
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val lp = container.layoutParams as WindowManager.LayoutParams
lp.flags = lp.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
lp.dimAmount = 0.3f
wm.updateViewLayout(container, lp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment