Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round a container in jetpack compose

I have a design to fulfill, which is an icon with a white background, which must be round. I have tried many possible ways but I have not been able to achieve that.

I attach the images and code of what I have done.

My current design:

enter image description here

How it should look:

enter image description here

My code:

Box(
    modifier = Modifier
        .background(Color.White)
        .clip(RoundedCornerShape(10.dp))
) {
    Icon(
        Icons.Outlined.StarOutline,
        modifier = Modifier
            .size(50.dp)
            .padding(10.dp),
        contentDescription = null
    )
}
like image 245
Jhonny Luis Avatar asked Sep 20 '25 04:09

Jhonny Luis


1 Answers

The order of the modifiers matters, for what you are trying to achieve the composable should be first clipped and then apply that white background:

Box(
    modifier = Modifier
        .clip(RoundedCornerShape(percent = 50))
        .background(Color.White)
) {
    Icon(
        Icons.Outlined.StarOutline,
        modifier = Modifier
            .size(50.dp)
            .padding(10.dp),
        contentDescription = null
    )
}

I've also set the RoundedCornerShape to 50% so that it's circular as in the desired output.

like image 122
jeprubio Avatar answered Sep 22 '25 17:09

jeprubio