Kotlin and Android Development featuring Jetpack: SwitchCompat's thumbTint and trackTint being ignored (page 76)

I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint.

As entered, the SwitchCompat changes color to holo_blue_bright when the switch is enabled and checked, but the colors specified for state_enabled=false and state_checked=false seem to be getting ignored.

I started by changing the first color (state_enabled=false) in ai_toggle_color.xml to holo_red_light, to make it blatantly obvious when it’s being used… then launched it in the Emulator (API 30):

SwitchCompat enabled=false, checked=moot: light gray (vs holo_red_light)

SwitchCompat enabled=true, checked=true: holo_blue_bright, as expected.

SwitchCompat enabled=true, checked=false: dark gray (vs holo_green_light)

Searching around on StackOverflow, I found a few posts that seem to suggest that this might be due to a theme or style overriding the colors set via thumbTint and trackTint.

I tried running the same set of experiments under the emulator using API 27, to see whether it might be due to a recent change in Android’s behavior. Same outcome.

As a final test, I loaded Chapter 3 from the zip archive directly into Android Studio, and ran it as-is in the emulator under API 30… and got the same results as before.

For whatever reason, SwitchCompat appears to be ignoring the color choices set by thumbTint and trackTint unless enabled and checked are both true.