Jetpack compose DropdownMenu With rounded Corners

6.1k views Asked by At

Hello I can't figure out how to make a cut corners menu in jetpack compose 1.0.0-beta02. I tried wrapping the while menu with a surface but It didn't work.

    TopAppBar(
        modifier = Modifier
            .statusBarsPadding(),
        title = {
            Text(text = "Title")
        },
        actions = {
            var menuExpanded by remember { mutableStateOf(false) }

            IconButton(onClick = { menuExpanded = true }) {
                Icon(Icons.Default.MoreVert, contentDescription = null)
            }

            DropdownMenu(
                expanded = menuExpanded,
                onDismissRequest = {
                    menuExpanded = false
                },
            ) {
                DropdownMenuItem(onClick = {}) {
                    Text("Item 2")
                }
            }
        },
    )

Which gives me

No Cut corners

But I need something like this, which is rounded.

menu with Material Theming

1

There are 1 answers

3
Gabriele Mariotti On BEST ANSWER

Using a M2 MaterialTheme theme, the default shape used by the DropdownMenu is defined by the medium attribute in the shapes used in the MaterialTheme (check your theme).

val Shapes = Shapes(
    small = RoundedCornerShape(4.dp),
    medium = RoundedCornerShape(4.dp),  //<- used by `DropdownMenu`
    large = RoundedCornerShape(0.dp)
)

You can change this value in your theme or you can override the medium shape only in your DropdownMenu.
Something like:

    MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(16.dp))) {
        DropdownMenu(
            expanded = menuExpanded,
            onDismissRequest = {
                menuExpanded = false
            }                
        ) {
            DropdownMenuItem(onClick = {}) {
                Text("Item 2")
            }
            DropdownMenuItem(onClick = {}) {
                Text("Item 3")
            }
        }
    }

enter image description here

Using a M3 MaterialTheme the default shape used by the DropdownMenu is defined by the extraSmall attribute in the shapes:

MaterialTheme(
    shapes = MaterialTheme.shapes.copy(extraSmall = RoundedCornerShape(16.dp))){

    //... DropdownMenu()

}