简体   繁体   中英

Jetpack compose DropdownMenu With rounded Corners

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

没有偷工减料

But I need something like this , which is rounded.

带有材质主题的菜单

With 1.0.0 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")
            }
        }
    }

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM