【问题标题】:How to change the width of dialog in android compose如何在android compose中更改对话框的宽度
【发布时间】:2021-11-08 14:32:18
【问题描述】:

似乎无法使用 Compose 更改对话框的宽度。 我最接近更改对话框宽度的是通过DialogProperties.usePlatformDefaultWidth。将其设置为 false 会导致对话框填满屏幕,但有没有办法使用自定义宽度?

【问题讨论】:

    标签: android kotlin dialog android-alertdialog android-jetpack-compose


    【解决方案1】:

    Use 可以使用带有texttitlebuttons 参数的构造函数定义自定义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 设置为 false 并且有效。与默认值相比,我可以增加或减少大小
    • 我认为要使修饰符起作用,您需要覆盖usePlatformDefaultWidth(即true)的默认值并将其设置为false。然后您可以使用modifier 增加(或减少)大小。
    • @Kofi 你是对的关于增加大小更新了答案。
    猜你喜欢
    • 1970-01-01
    • 2012-02-08
    • 2015-07-07
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 2023-02-08
    • 1970-01-01
    相关资源
    最近更新 更多