You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Compose中Material3 Card背景色设置报错咨询

Material3 Card 设置背景色报错的解决方法

在Material3 1.0.0-alpha14版本中,Card组件并没有backgroundColor这个参数——这是因为Material3的组件配色体系做了调整,背景色需要通过colors参数配合CardDefaults.cardColors()来配置,其中对应Card背景的属性是containerColor(容器色)。

修改后的可用代码如下:

Card(
    modifier = Modifier
        .fillMaxWidth()
        .padding(16.dp),
    // 通过CardDefaults配置Card背景色
    colors = CardDefaults.cardColors(
        containerColor = Color.Gray
    ),
    content = {
        Text(
            "Card with background color argument",
            modifier = Modifier.padding(16.dp),
            style = MaterialTheme.typography.labelLarge
        )
    }
)

如果需要配置Card在其他状态下的颜色(比如禁用、点击时),也可以在cardColors()中设置disabledContainerColor、pressedContainerColor等对应参数。

内容的提问来源于stack exchange,提问作者Bolt UIX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 20:09:21