android 如何删除@Composable Dialog默认水平填充

qxsslcnc  于 2023-08-01  发布在  Android
关注(0)|答案(1)|浏览(102)

我的代码看起来像这样

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(),
        ) {
        }
    }

字符串
我可以改变底部填充为0,它将是0,但无论我做什么,总是有水平填充像18dp,我怎么才能删除它?请不要建议使用AlertDialog

tjvv9vkg

tjvv9vkg1#

只需要添加参数:properties = DialogProperties(usePlatformDefaultWidth = false)以达到预期的效果。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(),
    ) {
    }
}

字符串
更多信息:https://developer.android.com/reference/kotlin/androidx/compose/ui/window/DialogProperties

相关问题