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

Material 3默认Icon/Button尺寸异常过大?M2与M3尺寸对比咨询

Material3 vs Material2控件尺寸差异及Button内边距调整方案

一、Material3默认控件尺寸更大是设计规范的既定变化

没错,Material3的默认控件尺寸确实比Material2更大——这是Google为提升触控友好性、适配大屏设备做出的设计调整。Google日历目前仍基于Material2规范开发,所以两者视觉上会有明显尺寸差。

二、Material2与Material3核心控件的默认尺寸差异

  • Button/TextButton:
    • Material2:填充按钮默认高度48dp,水平内边距16dp;TextButton内边距更小,适配文字按钮的轻量化视觉。
    • Material3:填充按钮默认高度52dp,水平内边距24dp;TextButton的默认内边距也同步增大,整体触控区域更宽。
  • Switch开关:
    • Material2:默认宽48dp、高24dp;
    • Material3:默认宽52dp、高32dp,触控热区也相应扩大。

三、Button/TextButton设置contentPadding未生效的解决方法

Material3的Button组件默认会继承主题中ButtonDefaults的配置,直接设置contentPadding可能被全局样式覆盖,你可以试试这两种方案:

  1. 显式指定自定义内边距
    直接在Button参数中传入自定义PaddingValues,强制覆盖默认值:
Button(
    onClick = { /* 点击逻辑 */ },
    contentPadding = PaddingValues(horizontal = 16.dp, vertical = 10.dp)
) {
    Text("示例按钮")
}

对于TextButton,同样的方式生效:

TextButton(
    onClick = { /* 点击逻辑 */ },
    contentPadding = PaddingValues(horizontal = 12.dp, vertical = 4.dp)
) {
    Text("文字按钮")
}
  1. 全局修改主题尺寸Token
    如果希望整个应用的控件尺寸统一贴近Material2,可以自定义Material3主题,覆盖对应的尺寸Token:
@Composable
fun MyCalendarTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme()
    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography(),
        content = content
    ) {
        // 全局覆盖按钮内边距
        ButtonDefaults.contentPadding = PaddingValues(horizontal = 16.dp, vertical = 12.dp)
        // 也可以针对TextButton单独设置
        ButtonDefaults.textButtonContentPadding = PaddingValues(horizontal = 12.dp, vertical = 4.dp)
    }
}

四、关于是否继续使用Material3的建议

如果你的核心需求是1:1复刻Google日历的视觉效果,切换到Material2会更直接;但如果想学习最新的Material Design规范,或者未来计划适配动态颜色、Material You等新特性,完全可以通过调整主题Token来让控件尺寸贴近Material2,不需要放弃Material3。

内容的提问来源于stack exchange,提问作者Siva Subramaniam

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 15:37:52