Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I align an Icon to top of Text?

enter image description here

This is how I want this to look like

enter image description here Notice that the text is always a number.

How can I align the top of the Heart to the red line (top of text)?

If I can remove the font padding (over the red line and below the number) this also could work for me fine but I do not know how to do this.

This is my code

Row {
            Text(
                pulse.toString(),
                modifier = Modifier
                    .background(Color.Gray),
                fontSize = 60.sp,
                color = vitalModifier.color)
            Spacer(modifier = Modifier.width(10.dp))
            Icon(
                modifier = Modifier
                    .background(Color.Green)
                    .alignBy(LastBaseline),
                painter = painterResource(R.drawable.ic_heart),
                contentDescription = null,
                tint = vitalModifier.color)
        }
like image 311
Solvek Avatar asked Oct 16 '25 15:10

Solvek


1 Answers

You can use BadgedBox to achieve this

BadgedBox(badge = { Badge { Text("8") } }) {
                    Icon(
                        Icons.Filled.Favorite,
                        contentDescription = "Favorite"
                    )
                }  
      
       

https://dev.to/farhanroy/jetpack-compose-badge-18ho

enter image description here

like image 90
Kunal Kalwar Avatar answered Oct 18 '25 08:10

Kunal Kalwar



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!