material-components/material-components-android

[BadgeDrawable] Color selector not being respected for badge background

開放

#2,764 建立於 2022年6月17日

 (1 則留言) (0 個反應) (0 位負責人)Java (3,023 個分叉)batch import
Good First IssueWidget: Badgefeature request

倉庫指標

星標
 (15,910 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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

貢獻者指南