Home > database >  How to use BadgeBox with new compose version?
How to use BadgeBox with new compose version?

Time:02-04

With Jetpack Compose version "1.0.1" I used Badge Box like This

BadgedBox(
    badgeContent = {
        Text(text = "5")
    },
    backgroundColor = Primary,
    modifier = Modifier
) {
      Icon(
          imageVector = Icons.Outlined.ShoppingCart,
          contentDescription = "shopping cart",
          tint = Color.Black
      )
}

But with Compose version "1.0.5" this code doesn't work

What is the new way to do it?

CodePudding user response:

Using badge attribute of BadgedBox and Badge Composable.

Example,

BadgedBox(
    badge = {
        Badge {
            Text(text = "5")
        }
    },
    // Other attributes remain same
) {
      // As it is
}

CodePudding user response:

With compose 1.1.x you can use:

BadgedBox(
    badge = { Badge { Text("5") } },
    modifier = Modifier.background(Red)) {
        Icon(
            Icons.Filled.Favorite,
            contentDescription = "Favorite"
        )
}

With compose 1.0.x you can use:

BadgeBox(
    badgeContent = { Text("5") },
    backgroundColor = Red,) {
       Icon(
           Icons.Filled.Favorite,
           contentDescription = "Favorite"
       )
}

With 1.1.x the BadgeBox was renamed to BadgedBox and some parameters were removed (check this commit).

  •  Tags:  
  • Related