Skip to content

Conversation

takahirom
Copy link
Owner

No description provided.

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)

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 })
}

Copy link
Owner Author

@takahirom takahirom Jun 14, 2025

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Base automatically changed from tm/add-before/2025-06-12 to main June 14, 2025 02:41
@takahirom takahirom marked this pull request as ready for review June 14, 2025 02:41
@takahirom takahirom merged commit c1c7e83 into main Jun 16, 2025
8 of 9 checks passed
@takahirom takahirom deleted the tm/add-dim-color-to-dialog/2025-06-13 branch June 16, 2025 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants