0

I have use the material bottom nav to add badge to its view, and I also able to change color by assigning simple color, but when I want to set that color based on selected state, the color doesn't change. same for badge text color, it doesn't change when I use selector color.

here is the code snippet:

val badge = bottomNavigation.getOrCreateBadge(R.id.cartIcon)
    badge.backgroundColor = getColor(R.color.badge_color_selector)

in my badge_color_selector.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/error_state" android:state_selected="false" />
    <item android:color="@color/white" android:state_selected="true" />
</selector>
  • That is because you do not need a color, but a state list. `getColorStateList()` returns a `ColorStateList`, are you able to set this to badge? – Michiel Nov 25 '21 at 22:19
  • @Michiel nope, the material badge doesn't have an option to setColorStateList, is there any other way to achieve what I want for badge? – Mickey Guo Nov 27 '21 at 13:56

0 Answers0