question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chip materialThemeOverlay is not working

See original GitHub issue

Description: The implementation with Chip in Material 3 is not working after following the documentation

Expected behavior: Should apply the styling based on what was stated in the documentation.

Source code:

Not working, incorrect color.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Chip style on both light and night mode -->
    <style name="AppChip" parent="Widget.Material3.Chip.Input">
        <item name="closeIconVisible">false</item>
        <item name="checkedIconVisible">false</item>
        <item name="materialThemeOverlay">@style/ThemeOverlay.App.Chip</item>
        <item name="shapeAppearanceOverlay">@style/ShapeAppearance.App.SmallComponent</item>
    </style>
    <style name="ThemeOverlay.App.Chip" parent="">
        <item name="colorOnSurfaceVariant">@color/chip_state_list</item>
        <item name="colorOnSurface">@color/background_color_chip_state_list</item>
    </style>
</resources>

Working correct color

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Chip style on both light and night mode -->
    <style name="AppChip" parent="Widget.Material3.Chip.Input">
        <item name="closeIconVisible">false</item>
        <item name="checkedIconVisible">false</item>
        <item name="android:textColor">@color/chip_state_list</item>
        <item name="chipStrokeColor">@android:color/transparent</item>
        <item name="chipBackgroundColor">@color/background_color_chip_state_list</item>
        <item name="shapeAppearanceOverlay">@style/ShapeAppearance.App.SmallComponent</item>
    </style>
    <!--TODO theme overlay-->
</resources>

Usage in main theme <item name="chipStyle">@style/AppChip</item>

Android API version: SDK 21

Material Library version: 1.6.0-beta-01

Device: Samsung J1

Is it just me or the Material 3 components and its documentations are not yet finish or finalize? I keep having this issue where the documentation and the behavior is not correct.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
drchencommented, Apr 19, 2022

I think it’s using colorOnSecondaryContainer (selected) and colorOnSurfaceVariant (unselected.)

0reactions
ArcherEmiya05commented, Apr 19, 2022

I doesn’t work because chipBackgroundColor doesn’t directly point to colorSurface.

The default value is a CSL which switches its color between colorSurface and colorSecondaryContainer. To make it work with materialThemeOverlay, you will need to override colorSurface and colorSecondaryContainer separately, instead of overriding colorSurface with an CSL.

It works! Thanks. How about for its text color?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Chip] materialThemeOverlay support · Issue #1003 - GitHub
Almost all library components support materialThemeOverlay, and developer can change ... but for some reason this is not implemented for chip.
Read more >
MaterialThemeOverlay - Android Developers
Utility to apply a theme overlay to any Context . The theme overlay is read from an attribute in the style. This is...
Read more >
Chips - Material Design
Chips are mostly commonly used in groups. We recommend using ChipGroup as it is purpose-built to handle multi-chip layout and behavior patterns (as...
Read more >
Material Chip chipStrokeColor is not being applied to Chip ...
I am using Material Chips from the Material Components Library: com.google.android.material:material:1.1.0 I have created styles for Chips ...
Read more >
The components of Material Design (Android Dev Summit '18)
Material Theming launched this year at Google I/O, enabling you to systematically customize Material Design to better reflect your product's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found