Created
July 10, 2019 22:21
-
-
Save kakajika/5f0f857a415eb278633cd43127b223ae to your computer and use it in GitHub Desktop.
PopupWindow with dim background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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