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

Jetpack Compose中Material3 Alpha16版本下如何修改ModalNavigationDrawer抽屉容器颜色?

解决Material3 1.0.0-alpha16中抽屉容器颜色设置问题

在Material3 1.0.0-alpha16版本中,抽屉组件的参数结构发生了调整:原有的drawerContainerColor参数被移除,转而通过drawerColors参数统一配置抽屉的颜色属性。

你之前尝试的scrimColor仅用于设置抽屉打开时覆盖主内容区的遮罩颜色,并非抽屉容器本身的颜色,所以不会改变抽屉背景。

正确的做法是使用DrawerDefaults.drawerColors()构造颜色配置,指定containerColor来设置抽屉容器的颜色,示例代码如下:

import androidx.compose.material3.DrawerDefaults
import androidx.compose.material3.ModalDrawer
import androidx.compose.ui.graphics.Color

ModalDrawer(
    drawerContent = { /* 你的抽屉内容 */ },
    drawerColors = DrawerDefaults.drawerColors(containerColor = Color.Red),
    // 其他必要参数(如drawerState等)
) {
    // 主内容区域
}

如果使用的是PersistentDrawer,同样适用该配置方式,只需将ModalDrawer替换为PersistentDrawer即可。

内容的提问来源于stack exchange,提问作者Always Learner

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 18:58:04