Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid BadgedBox get clipped in combination with IconButton

IconButton(onClick = onClick) {
        BadgedBox(
            badge = {
                    Badge {
                        Text("2")
                    }
            },
        ) {
            Icon(
                imageVector = Icons.Outlined.Notifications,
            )
        }
    }

This code leads to this:

BadgedIcon clipped

like image 942
David Avatar asked Oct 30 '25 10:10

David


1 Answers

Box {
    IconButton(onClick = onClick) {
        Icon(
            imageVector = Icons.Outlined.Notifications,
            contentDescription = "Notifications",
        )
    }
    Badge(
        modifier = Modifier
            .align(Alignment.TopEnd)
    ) {
        Text("2")
    }
}

enter image description here

  • Box is used as a parent container that holds both the IconButton and the Badge. This allows you to overlay the Badge over the IconButton without clipping.
  • Modifier.align(Alignment.TopEnd) positions the Badge at the top-right corner of the Box, above the IconButton.

This way, the badge is fully visible and no longer gets clipped.

like image 79
DevAndroid Avatar answered Nov 02 '25 00:11

DevAndroid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!