Jetpack compose Box layout clip showing white background

3.8k Views Asked by At

Compose Box layout showing white background when applying Clip Option

Box layout Showing white background when clip apply

Box( modifier = Modifier        
    .size(50.dp)
    .clip(CircleShape)
    .background(colorResource(id = R.color.black_trans))
)

Is there any way to transparent the background when CircleClip is applied?

3

There are 3 best solutions below

0
JungleLiu On
Box( modifier = Modifier        
    .size(50.dp)
    .background(colorResource(id = R.color.black_trans))
    .clip(CircleShape)
)

https://developer.android.com/jetpack/compose/modifiers

0
Nikhil Dupally On

In Jetpack Compose the order of the modifiers matters. So add background color first and then clip.

Box( modifier = Modifier        
.size(50.dp)
.background(colorResource(id = R.color.black_trans))
.clip(CircleShape)
)

Modifier Reference: https://developer.android.com/jetpack/compose/modifiers#order-modifier-matters

0
Aftab Bhadki On
Box(
                modifier = Modifier
                    .size(100.dp)
                    .clip(RoundedCornerShape(25))
                    .background(Color.Blue)

In Modifier order metters so we have to add background at last.