kotlin Jetpack编写-无法更改AlertDialog白色窗口背景

slhcrj9b  于 2023-02-09  发布在  Kotlin
关注(0)|答案(3)|浏览(199)

我是Kotlin多平台桌面开发的新手,我正在使用合成来构建UI。我有一个自定义的圆形背景的AlertDialog,问题是,它仍然有白色的角落,我不能删除某些原因。对话框:

我编写的代码就是为了实现这个目的:

AlertDialog(
        title = { Text("თქვენ ტოვებთ პროგრამას") },
        text = { Text("ნამდვილად გსურთ პროგრამიდან გასვლა?") },
        onDismissRequest = {},
        backgroundColor = Colors.DARKER_GRAY,
        contentColor = Colors.WHITE,
        shape = RoundedCornerShape(16.dp),
        confirmButton = {
            TextButton(onClick = onPositiveClick) {
                Text(text = "დიახ", color = Colors.RED)
            }
        },
        dismissButton = {
            TextButton(onClick = onNegativeClick) {
                Text(text = "არა", color = Colors.LIGHTER_GRAY)
            }
        },
        modifier = Modifier.defaultMinSize(300.dp).border(0.dp, Color.Transparent, RoundedCornerShape(0))
    )

有人知道我该怎么解决这个问题吗?提前谢谢你。

tyu7yeag

tyu7yeag1#

如果我可以问你,这是预览吗?因为如果我把你的代码 Package 成一列,改变它的背景颜色,然后运行它,它会完美地工作。

Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Red),
        verticalArrangement = Arrangement.SpaceEvenly,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
///Your code is here
        AlertDialog(
            title = { Text("თქვენ ტოვებთ პროგრამას") },
            text = { Text("ნამდვილად გსურთ პროგრამიდან გასვლა?") },
            onDismissRequest = {},
            backgroundColor = Color.Gray,
            contentColor = Color.White,
            shape = RoundedCornerShape(16.dp),
            confirmButton = {
                TextButton(onClick = { /*onPositiveClick*/ }) {
                    Text(text = "დიახ", color = Color.Red)
                }
            },
            dismissButton = {
                TextButton(onClick = { /*onNegativeClick*/ }) {
                    Text(text = "არა", color = Color.LightGray)
                }
            },
            modifier = Modifier
                .defaultMinSize(300.dp)
                .border(0.dp, Color.Transparent, RoundedCornerShape(0))
        )
    }
dfty9e19

dfty9e192#

这个错误与原生的Android主题颜色有关,只需更改主题的背景颜色即可:

<item name="android:background">@android:color/transparent</item>
laik7k3q

laik7k3q3#

尝试添加相同的形状大小到修改器的边框,因为你应用到对话框的形状:

modifier = Modifier.defaultMinSize(300.dp).border(0.dp, Color.Transparent, RoundedCornerShape(16.dp))

或者您可以删除它。AlertDialogs没有边界。
也许Android和桌面之间可能有区别,你真的需要.
至少从Android的Angular 来看,这是没有必要的。
წარმატება!

相关问题