Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compose Desktop AlertDialog rounded corners

In a compose desktop application I'm displaying an AlertDialog with rounded corners shape but there still appears a white rectangle at the corners.

Here is my code:

AlertDialog(
    modifier = Modifier
        .size(280.dp, 260.dp)
        .shadow(elevation = 20.dp),
    onDismissRequest = {},
    buttons = {
        Button(
            modifier = Modifier.padding(start = 100.dp, top = 0.dp),
            onClick = { onClose() }
        ) {
            Text(
                text = "OK",
                textAlign = TextAlign.Center
            )
        }
    },
    title = {
        Text(
            "A Title"
        )
    },
    text = {
        Column(
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text("Some Text")
        }
    },
    shape = RoundedCornerShape(24.dp),
    backgroundColor = Color.Red
)

How can I get rid of the background white corners that are visible behind the dialog.

like image 486
Bruciew Avatar asked Dec 17 '25 05:12

Bruciew


1 Answers

I was having an issue with .clip() not working because of the fact that Order of modifiers matters, the .clip() effect was being overwritten by my .background() modifier.

This doesn't work:

modifier = Modifier
    .background(MyTheme.colors.background)   // overwrites .clip()
    .clip(RoundedCornerShape(28.dp)),        // .clip() evaluated first

This does work:

modifier = Modifier
    .clip(RoundedCornerShape(28.dp))         // then we can safely .clip()
    .background(MyTheme.colors.background),  // .background() evaluated first

Here is what the AlertDialog code looks like:

AlertDialog(
    modifier = Modifier
        .clip(RoundedCornerShape(28.dp))
        .background(MyTheme.colors.background),
    onDismissRequest = { /* On Dismiss */ },
    text = { /* Text */ },
    buttons = { /* Buttons */ },
    title = { /* Title * / },
)

Just remember that the order of the modifiers is of significant importance.

like image 100
tyler Avatar answered Dec 21 '25 08:12

tyler



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!