Andrey Kijonok
Andrey Kijonok

Reputation: 416

How can I remove @Composable Dialog default horizontal padding

My code looks something like this

    Dialog(onDismissRequest = {}) {
        val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider
        dialogWindowProvider.window.setGravity(Gravity.BOTTOM)

        Surface(
            shape = RoundedCornerShape(16.dp),
            elevation = 0.dp,
            color = Color.Transparent,
            modifier = Modifier
                .padding(bottom = 24.dp)
                .fillMaxWidth(),
        ) {
        }
    }

I can change bottom padding to 0 and it will be 0 but no matter what I do, there is always horizontal padding like 18dp, how can I remove it? Please don't suggest to use AlertDialog

Upvotes: 0

Views: 389

Answers (1)

Thiên Ân
Thiên Ân

Reputation: 46

You only need to add the parameter: properties = DialogProperties(usePlatformDefaultWidth = false) to achieve the expected result. Image result

Dialog(onDismissRequest = {}, properties = DialogProperties(usePlatformDefaultWidth = false)) {
    val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider
    dialogWindowProvider.window.setGravity(Gravity.BOTTOM)

    Surface(
        shape = RoundedCornerShape(16.dp),
        elevation = 0.dp,
        color = Color.Transparent,
        modifier = Modifier
            .padding(bottom = 24.dp)
            .fillMaxWidth(),
    ) {
    }
}

For more information: https://developer.android.com/reference/kotlin/androidx/compose/ui/window/DialogProperties

Upvotes: 2

Related Questions