Моя цель — сделать так, чтобы каждый DropdownMenuItem в сопровождающем ExpedDropdownMenu точно соответствовал этой высоте 48.dp для обеспечения единообразного визуального интервала.
Несмотря на попытку изменить contentPadding и применить Modifier.size, компоненты DropdownMenuItem по-прежнему кажутся выше, чем 48.дп.
Код: Выделить всё
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AutoCompleteTextFields(
modifier: Modifier = Modifier,
value: String,
onValueChange: (String) -> Unit,
genderList: List = listOf("Female", "Male"),
) {
// State to control the visibility of the dropdown menu
var isExpanded by remember { mutableStateOf(false) }
Column(
modifier = modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
ExposedDropdownMenuBox(
expanded = isExpanded,
onExpandedChange = {
isExpanded = it
},
) {
Row(
modifier = Modifier.fillMaxWidth(),
) {
TextField(
value = value,
onValueChange = {
onValueChange(it)
// Show the dropdown when the text field is updated
isExpanded = true
},
trailingIcon = {
ExposedDropdownMenuDefaults.TrailingIcon(expanded = isExpanded)
},
modifier =
Modifier.height(48.dp)
.menuAnchor(ExposedDropdownMenuAnchorType.SecondaryEditable),
)
}
ExposedDropdownMenu(
expanded = isExpanded,
onDismissRequest = { isExpanded = false },
shape = RoundedCornerShape(4.dp),
) {
genderList.forEachIndexed { index, item ->
DropdownMenuItem(
modifier = Modifier.height(48.dp),
text = {
Text(
item,
style =
MaterialTheme.typography.bodyLarge.copy(
color = Color.White,
),
)
},
onClick = {
onValueChange(
item,
)
isExpanded = false
},
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 0.dp),
)
}
}
}
}
}

Подробнее здесь: https://stackoverflow.com/questions/798 ... wnmenuitem