material-components/material-components-android

[BadgeDrawable] Color selector not being respected for badge background

Open

#2 764 ouverte le 17 juin 2022

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)Java (3 023 forks)batch import
Good First IssueWidget: Badgefeature request

Métriques du dépôt

Stars
 (15 910 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Description: Adding a color selector to the badgeStyle -> backgroundColor doesn't see to work as expected. Color doesn't change when Tab is selected.

Expected behavior: Badge color would respect color selector

Source code:

I've tried every single property I could find, and it didn't make a difference. Here's a sample example:

<style name="StudioBadge" parent="Widget.MaterialComponents.Badge">
    <item name="backgroundColor">@color/badge_bg</item>
    <item name="badgeTextColor">@color/badge_text</item>
</style>

And badge_bg looks like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="@color/color_one"/>
    <item android:color="@color/color_two"/>
</selector>

In this example, only color_two gets applied to the badge, even though following the same process the tab text changes accordingly.

Android API version: 12

Material Library version: 1.4.0

Device: Samsung S20 & Pixel 1

Guide contributeur