-
Notifications
You must be signed in to change notification settings - Fork 42
Add dim color to dialog #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if ((layoutParams.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND) !== 0) { | ||
val alpha = (layoutParams.dimAmount * 255).toInt() | ||
val color = Color.argb(alpha, 0, 0, 0) | ||
decorView.setBackgroundColor(color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we can't use decorView
here as it's only wrapping the size of the dialog body.
I noticed that this was in layoutlib, not the actual WindowManagerImpl running on Android; so they're just mimicking the behaviour of a Dimmer. So I think it's reasonable to do something similar here, I tried the following and it produced the desired results:
if ((layoutParams.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND) !== 0) {
val alpha = (layoutParams.dimAmount * 255).toInt()
val color = Color.argb(alpha, 0, 0, 0)
canvas.drawRect(Rect(0, 0, width, height), Paint().apply { this.color = color })
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. It seems to be working correctly now. I had initially tried this, but I misunderstood and thought the semi-transparent color was filling the area with a solid color. However, I now realize that it is being drawn with the proper transparency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
No description provided.