【发布时间】:2021-11-08 14:32:18
【问题描述】:
似乎无法使用 Compose 更改对话框的宽度。
我最接近更改对话框宽度的是通过DialogProperties.usePlatformDefaultWidth。将其设置为 false 会导致对话框填满屏幕,但有没有办法使用自定义宽度?
【问题讨论】:
标签: android kotlin dialog android-alertdialog android-jetpack-compose
似乎无法使用 Compose 更改对话框的宽度。
我最接近更改对话框宽度的是通过DialogProperties.usePlatformDefaultWidth。将其设置为 false 会导致对话框填满屏幕,但有没有办法使用自定义宽度?
【问题讨论】:
标签: android kotlin dialog android-alertdialog android-jetpack-compose
Use 可以使用带有text、title 和buttons 参数的构造函数定义自定义AlertDialog,并应用size(例如使用Modifier.size)并覆盖usePlatformDefaultWidth = false 的默认行为:
AlertDialog(
onDismissRequest = { /*TODO*/ },
title = {
Text(text = "Title")
},
text = {
Text(
"This area typically contains the supportive text " +
"which presents the details regarding the Dialog's purpose."
)
},
buttons = {},
properties = DialogProperties(
usePlatformDefaultWidth = false
),
modifier = Modifier.size(200.dp,250.dp)
)
【讨论】:
usePlatformDefaultWidth(即true)的默认值并将其设置为false。然后您可以使用modifier 增加(或减少)大小。