Closed interblitz closed 4 years ago
Hi @interblitz, it looks like this is due to the colorSurface
/colorOnSurface
compositing that Chip does to arrive at its default background color, as per the Material spec:
Elevation overlays are only applied to UI elements with a background that matches the colorSurface
hex value (ignoring alpha), and in this case I guess the final blended colorSurface
/colorOnSurface
value doesn't match colorSurface
, so by default the overlay is not applied.
One possible workaround for dark theme is to set app:chipBackgroundColor="@empty"
on your Chip and then give it some android:elevation
. That will result in the elevation overlay being applied in dark theme. For example:
Hi @dsn5ft,
Thank you for clarifications. I have one more related issue :) When chips are placed in the bottom sheet layout (linear layout with layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior") an elevation applied unexpectedly (see chips at the bottom). This confuses chips usage...
All layouts and java code is the same, only main activity layout changed, layout_bottom_sheet added.
<LinearLayout
android:id="@+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="35dp"
android:orientation="vertical"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
app:behavior_peekHeight="100dp"
app:behavior_hideable="false"
>
<include layout="@layout/activity_main_item"/>
</LinearLayout>
Main activity layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/dialogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bottom sheet dialog"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Linear layout" />
<include layout="@layout/activity_main_item"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Material card" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<include layout="@layout/activity_main_item"/>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="35dp"
android:orientation="vertical"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
app:behavior_peekHeight="100dp"
app:behavior_hideable="false"
>
<include layout="@layout/activity_main_item"/>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
No problem.
Re: your related issue, I'm not following. Looking at your screenshot, I don't see what you mean by "an elevation applied unexpectedly". Can you explain more?
Due to mtrl_chip_background_color selector expected behavior of chips is skipping parents elevation. But when chips are placed in layout with app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" their background suddenly becomes lighter, so my guess is elevation overlay is applied. This is a bit confusing. That what I mean.
I'm sorry but I'm still not really following. When I compare the background colors of the chips in your first screenshot, I see that the "Not styled1" chip's background is rgb(60, 60, 60) and the other chip ("Entry", "Action", etc.) backgrounds are rgb(42, 42, 42), regardless of whether they're in the "Linear layout", "Material card", or bottom sheet layout. So to me it doesn't seem like the chips are lighter within the layout that has app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior".
You are right, color picker says background colors are same. I'm really sorry for wasting your time.
Description:
Made simple test project with dark theme, bottom sheet dialog and chips. On the first screenshot chips at the main activity are lighter then parent layout, but on the second one chips are darker. It seems to be a bug or I've missed something?
Expected behavior:
Background of chips at the bottom sheet dialog should be lighter.
Source code:
Main activity layout
activity_main_item layout
Main activity code:
Android API version: 22 - 29
Material Library version: 1.2.1
Device: Emulator