https://kotlinlang.org logo
#compose
Title
# compose
l

Landry Norris

08/19/2022, 6:02 PM
Does material specifically forbid alpha in the popup for a dropdown menu? It appears that ExposedDropDownMenu does not support this, so I had to copy the source code from
ExposedDropDownMenu
,
AndroidMenu
,
ExposedDropDownMenuPopup
, and
Menu
and explicitly handle the case where the popup background should have alpha. Is this a bug in Compose, where I should contribute the ‘fix’, or is this expected behavior? For reference, if you set Modifier.background to a color with alpha on ExposedDropDownMenu, you can see there is always an opaque white background applied behind.
c

Chris Sinco [G]

08/19/2022, 6:55 PM
It’s not explicitly forbidden but it is implicitly not recommended as the design specs don’t have any indication of using transparency in menus and overlays. Is this a design requirement for your app?
l

Landry Norris

08/19/2022, 6:56 PM
Yes. I need the dropdown to have an alpha of 0.611
c

Chris Sinco [G]

08/19/2022, 6:56 PM
Also FWIW, adding transparency to the background of a menu or overlay in Compose will not be a great result because of shadow which is also in those components. Applying an alpha will expose the shadow layer behind which is not desirable. This is likely why there is still an opaque background applied behind.
l

Landry Norris

08/19/2022, 6:56 PM
For now, I created a package and copied the relevant sources of ExposedDropDownMenu, then added an alpha to PopupLayout
c

Chris Sinco [G]

08/19/2022, 6:59 PM
I see - what does it look like now (assuming you removed the opaque background)?
l

Landry Norris

08/19/2022, 6:59 PM
I can see the content that is behind the dropdown menu now. It looks like a normal popup with alpha. I did have to apply the alpha to the whole popup, not the background color, so I can’t have anything fully opaque. I tried setting the background color of the PopupLayout, which is what the design specs wanted, but that didn’t seem to work. I’m just going to see if the design team is happy with the text in the options being partially transparent too.
c

Chris Sinco [G]

08/19/2022, 7:00 PM
Curious, do you have a mock of the intended design?
l

Landry Norris

08/19/2022, 7:02 PM
Not currently. We’re between design tools right now, so I just got a verbal description. The drop down should let the user choose between several options. The background color of the dropdown’s popup is supposed to be black with an alpha of 0.611 and the text should be white.
c

Chris Sinco [G]

08/19/2022, 7:03 PM
Gotcha. 0.611 is quite specific…
l

Landry Norris

08/19/2022, 7:04 PM
I may take some time some weekend and see if I can get it properly working where the background can have alpha, instead of applying it to the whole popup. Would this be something that I should make a PR for on compose-ui if I can figure it out?
c

Chris Sinco [G]

08/19/2022, 7:19 PM
I’m not sure it would be accepted since the decision to NOT have alpha in menus is based on the Material Design spec and also seems to be an Android OS wide decision as well (implicitly at least when I look at the many menus/overlays/dialogs). So I’m not sure we’d accept this into the core since it seems this is a design decision meant for an individual app.
I think it may be better to create a feature request so we can track if other developers/apps would like this functionality, and then we’ll decide accordingly how to execute in the core libraries
l

Landry Norris

08/19/2022, 7:39 PM
Sounds good. I’d assume I need to use the google sources androidx repo to create the feature request?
c

Chris Sinco [G]

08/19/2022, 7:47 PM
Oh I meant on Issue Tracker. But creating a pull request is also helpful if it’s not too much effort, and yes that’d be on androidx
l

Landry Norris

08/19/2022, 7:48 PM
Sorry, I meant issue tracker too. Creating an issue now and marking it as a feature request.
c

Chris Sinco [G]

08/19/2022, 9:02 PM
Thanks!
3 Views