Android material 3 has introduced elevation overlays(tonal color overlays). Which causes background color change for MaterialCard views if android:elevation
is provided or increased and impacts the original background color.
- How to style material 3 elevation overlays?
- How to disable material 3 elevation overlays to avoid background color change for card views if elevation is provided to the view.
Documentation doesn't provide much information related to styling or disabling elevation overlays.
https://developer.android.com/jetpack/compose/designsystems/material3#elevation https://m3.material.io/styles/elevation/applying-elevation
As you can find in the doc:
It is managed by the library.
Just an example with a
MaterialCardView
withapp:cardElevation="4dp"
andapp:cardElevation="8dp"
.Light mode:
Dark mode:
The overlay is based on the
colorOnSurface
defined in the app theme.You can change this color adding in the app theme:
You can also disable this behavior using in the app theme:
Many components in the Material Components Library support elevation overlays in dark theme but you can also apply it in your custom view using using the
MaterialShapeDrawable
.For example you can use a
LinearLayout
: