Material Design 3 如何禁用高程叠加?

Kha*_*dov 4 android material-design material-components-android android-dark-theme material-design-3

Android Material 3引入了海拔覆盖(色调颜色覆盖)。如果提供或增加,则会导致 MaterialCard 视图的背景颜色发生变化android:elevation,并影响原始背景颜色。

  1. 如何设置材质 3 立面叠加层的样式?
  2. 如果向视图提供了标高,如何禁用材质 3 标高叠加以避免卡片视图的背景颜色更改。

文档没有提供太多与样式或禁用高程覆盖相关的信息。

https://developer.android.com/jetpack/compose/designsystems/material3#elevation https://m3.material.io/styles/elevation/applying-elevation

Gab*_*tti 16

正如您在文档中可以找到的:

深色主题中,标高叠加层是半透明的白色 ( colorOnSurface) 叠加层,概念上放置在表面颜色的顶部。

由图书馆管理
只是一个MaterialCardViewwithapp:cardElevation="4dp"和 的例子app:cardElevation="8dp"

灯光模式:

在此输入图像描述

深色模式:

在此输入图像描述

叠加层基于colorOnSurface应用程序主题中的定义。
您可以在应用程序主题中添加更改此颜色:

<item name="elevationOverlayColor">@color/...</item>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

您还可以在应用程序主题中使用禁用此行为:

<item name="elevationOverlayEnabled">false</item>
Run Code Online (Sandbox Code Playgroud)

材质组件库中的许多组件支持深色主题中的标高叠加,但您也可以使用MaterialShapeDrawable.

例如,您可以使用LinearLayout

LinearLayout linearLayout1= findViewById(R.id....);
MaterialShapeDrawable shapeDrawableLL1 = 
MaterialShapeDrawable.createWithElevationOverlay(this, 4.0f );
ViewCompat.setBackground(linearLayout1,shapeDrawableLL1);

LinearLayout linearLayout2= findViewById(R.id....);
MaterialShapeDrawable shapeDrawableLL2 = 
MaterialShapeDrawable.createWithElevationOverlay(this, 16.0f );
ViewCompat.setBackground(linearLayout2,shapeDrawableLL2);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 非常感谢您的回答。我现在明白多了 (2认同)