android - How to reduce height of a composable to wrap content without padding - Stack Overflow

时间: 2025-01-06 admin 业界

I'm using DropDownMenuItem with a Text in a DrowpDownMenu, and I need to reduce the DropDownMenuItem height to the height of the Text, or with a minimum padding of 2.dp. Now the height of the DropDownMenuItem is very big on big screens. Is double of the height of the Text. Also, the parent DrowpDownMenu is adding even more height. How can that height be reduced to the Text height?

DropdownMenu(
    modifier = Modifier.background(Color.Yellow),
    expanded = expandedFile,
    onDismissRequest = { expandedFile = false }
) {
    DropdownMenuItem(
        modifier = Modifier.background(Color.Blue),
        text = {
            Text(
                modifier = Modifier.background(Color.Red),
                text = stringResource(Res.string.exit)
            )
        }
    )
}

I tryed all this:

DropdownMenuItem(modifier = Modifier.background(Color.Blue).padding(0.dp)
.sizeIn(minHeight = 0.dp).height(IntrinsicSize.Min),
 contentPadding = PaddingValues(0.dp),

None worked