下拉菜单的圆角组成android

问题描述 投票:0回答:2

之前,我在这里发帖,我用谷歌搜索了很多。我发现以下内容:

MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(16.dp))){}
来自以下SO帖子:Jetpack compose DropdownMenu With rounded Corners

编辑:我正在使用Material Design v3。


  MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(16.dp))) {
            IconButton(
                            onClick = { showMenu = !showMenu }) {
                            Icon(imageVector = Icons.Outlined.MoreVert, contentDescription = "")
                            DropdownMenu(
                                expanded = showMenu,
                                onDismissRequest = { showMenu = false },
                                modifier = Modifier.background(MaterialTheme.colorScheme.background).padding(4.dp)
                            ) {
                                DropdownMenuItem(text = { Text("Refresh", fontSize = 16.sp) },  onClick = { showMenu = false })
                                DropdownMenuItem(text = { Text("Settings", fontSize = 16.sp) },  onClick = { showMenu = false })
                                Divider(color = Color.LightGray, thickness = 1.dp)
                                DropdownMenuItem(text = { Text("Send Feedback", fontSize = 16.sp) },  onClick = { showMenu = false })
                            }
                        }
        }

目前它产生以下输出:

enter image description here

确实有一定的边界半径,但没有达到预期的目标。来自第三方应用程序的第二个屏幕截图确实具有我想要获得的边框半径。

enter image description here

android android-jetpack-compose android-jetpack-compose-material3 android-compose-dropdownmenu
2个回答
7
投票

对于material3,

DropdownMenu
使用的默认形状由形状中的
extraSmall

属性定义

你必须使用:

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

    //... DropdownMenu()

}

enter image description here


0
投票

根据 compsoe 1.7.5 现在支持使用形状道具自定义专用形状

@Composable
fun DropdownMenu(
    expanded: Boolean,
    onDismissRequest: () -> Unit,
    modifier: Modifier = Modifier,
    offset: DpOffset = DpOffset(0.dp, 0.dp),
    scrollState: ScrollState = rememberScrollState(),
    properties: PopupProperties = DefaultMenuProperties,
    shape: Shape = MenuDefaults.shape,
    containerColor: Color = MenuDefaults.containerColor,
    tonalElevation: Dp = MenuDefaults.TonalElevation,
    shadowElevation: Dp = MenuDefaults.ShadowElevation,
    border: BorderStroke? = null,
    content: @Composable ColumnScope.() -> Unit
): Unit

材质 3 下拉菜单

© www.soinside.com 2019 - 2024. All rights reserved.