简体   繁体   English

调整 Jetpack Compose 中 Material Design 3 组件的色调提升?

[英]Adjust Tonal Elevation for Material Design 3 Components in Jetpack Compose?

Is it possible to adjust the tonalElevation (but not the shadowElevation) of Material Design 3 components?是否可以调整 Material Design 3 组件的 tonalElevation(但不是 shadowElevation)?

It looks as though it's only possible to adjust both.看起来好像只能同时调整两者。 Below is the implementation of a Floating Action Button in Material Design 3. The same problem exists with other components.下面是 Material Design 3 中浮动操作按钮的实现。其他组件也存在同样的问题。

@Composable
fun FloatingActionButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    shape: Shape = FabPrimaryTokens.ContainerShape,
    containerColor: Color = FabPrimaryTokens.ContainerColor.toColor(),
    contentColor: Color = contentColorFor(containerColor),
    elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),
    content: @Composable () -> Unit,
) {
    Surface(
        onClick = onClick,
        modifier = modifier,
        shape = shape,
        color = containerColor,
        contentColor = contentColor,
        tonalElevation = elevation.tonalElevation(interactionSource = interactionSource).value,
        shadowElevation = elevation.shadowElevation(interactionSource = interactionSource).value,
        interactionSource = interactionSource,
    ) {
        CompositionLocalProvider(LocalContentColor provides contentColor) {
            // Adding the text style from [ExtendedFloatingActionButton] to all FAB variations. In
            // the majority of cases this will have no impact, because icons are expected, but if a
            // developer decides to put some short text to emulate an icon, (like "?") then it will
            // have the correct styling.
            ProvideTextStyle(
                MaterialTheme.typography.fromToken(ExtendedFabPrimaryTokens.LabelTextFont),
            ) {
                Box(
                    modifier = Modifier
                        .defaultMinSize(
                            minWidth = FabPrimaryTokens.ContainerWidth,
                            minHeight = FabPrimaryTokens.ContainerHeight,
                        ),
                    contentAlignment = Alignment.Center,
                ) { content() }
            }
        }
    }
}

There's an extension function on a ColorScheme class, that converts an Elevation into a Color: surfaceColorAtElevation() . ColorScheme 类上有一个扩展函数,可将 Elevation 转换为 Color: surfaceColorAtElevation()

TextField(
    ...
    colors = TextFieldDefaults.textFieldColors(
        containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)
    )
)

Also, there are six different Elevation levels in Material 3 ( https://m3.material.io/styles/elevation/tokens ):此外,Material 3 ( https://m3.material.io/styles/elevation/tokens ) 中有六个不同的海拔级别:

Level 0: 0dp
Level 1: 1dp
Level 2: 3dp
Level 3: 6dp
Level 4: 8dp
Level 5: 12dp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jetpack Compose 图标阴影/高度 - Jetpack Compose icon shadow/elevation 为什么我的 JetPack 撰写文本这么大(材料设计) - Why is my JetPack compose text so big (material design) 为什么 jetpack compose elevation 剪辑我的影子? - Why jetpack compose elevation clip my shadow? 如何在 Jetpack Compose 中为 ExtendedFloatingActionButton 设置默认高度 - How to set default elevation for ExtendedFloatingActionButton in Jetpack Compose Android资料设计 - LinearLayout提升 - Android material design - LinearLayout elevation 当我使用 Jetpack Compose 时,Material Components 是否提供编辑文本对话框? - Does Material Components provide edit text dialog when I use Jetpack Compose? Jetpack Compose:自定义 TextField 设计 - Jetpack Compose: Custom TextField design 如何禁用 Jetpack Compose 和 Material Design 3 中导航栏项目的涟漪效应? - How to disable ripple effect on Navigation Bar Items in Jetpack Compose and Material Design 3? Jetpack Compose 使用箭头和边框/高度创建聊天气泡 - Jetpack Compose create chat bubble with arrow and border/elevation 如何在 Jetpack Compose 中实现现代 Card 组件(a'la Material Design 3.0) - How to implement modern Card component (a'la Material Design 3.0) in Jetpack Compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM