material-components/material-components-android · error · IllegalStateException
The inactive and active parts of the track are different col
Error message
The inactive and active parts of the track are different colors. Use the getInactiveTrackColor() and getActiveTrackColor() methods instead.
What it means
IllegalStateException thrown by getTrackTintList() when trackColorInactive and trackColorActive differ. As with ticks, the combined getter is only valid when both track halves share one ColorStateList; otherwise use getTrackInactiveTintList() and getTrackActiveTintList().
Source
Thrown at lib/java/com/google/android/material/slider/BaseSlider.java:1998
}
}
/**
* Returns the color of the track if the active and inactive parts aren't different.
*
* @throws IllegalStateException If {@code trackColorActive} and {@code trackColorInactive} have
* been set to different values.
* @see #setTrackTintList(ColorStateList)
* @see #setTrackInactiveTintList(ColorStateList)
* @see #setTrackActiveTintList(ColorStateList)
* @see #getTrackInactiveTintList()
* @see #getTrackActiveTintList()
* @attr ref com.google.android.material.R.styleable#Slider_trackColor
*/
@NonNull
public ColorStateList getTrackTintList() {
if (!trackColorInactive.equals(trackColorActive)) {
throw new IllegalStateException(
"The inactive and active parts of the track are different colors. Use the"
+ " getInactiveTrackColor() and getActiveTrackColor() methods instead.");
}
return trackColorActive;
}
/**
* Sets the color of the track.
*
* @see #setTrackInactiveTintList(ColorStateList)
* @see #setTrackActiveTintList(ColorStateList)
* @see #getTrackTintList()
* @attr ref com.google.android.material.R.styleable#Slider_trackColor
*/
public void setTrackTintList(@NonNull ColorStateList trackColor) {
setTrackInactiveTintList(trackColor);
setTrackActiveTintList(trackColor);
}View on GitHub (pinned to ac7e18efee)
Solutions
- Use getTrackInactiveTintList() and getTrackActiveTintList() for the two halves.
- If one color is intended, call setTrackTintList(color) so both fields are set together.
- Audit shared style code that assumes getTrackTintList() never throws.
Example fix
// before ColorStateList track = slider.getTrackTintList(); // throws when halves differ // after ColorStateList inactive = slider.getTrackInactiveTintList(); ColorStateList active = slider.getTrackActiveTintList();
Defensive patterns
Strategy: validation
Validate before calling
ColorStateList inactive = slider.getTrackInactiveTintList(); ColorStateList active = slider.getTrackActiveTintList(); // avoid getTrackTintList() unless both were set via setTrackTintList()
Try / catch
In shared helpers: try { cs = slider.getTrackTintList(); } catch (IllegalStateException e) { cs = slider.getTrackActiveTintList(); } Prevention
- Use the split getters when themes differentiate track halves.
- Use setTrackTintList() (combined) when one color is intended.
When it happens
Trigger: Setting app:trackColorInactive and app:trackColorActive to different colors (or setTrackInactiveTintList(a)/setTrackActiveTintList(b)), then calling getTrackTintList().
Common situations: Material theming that deliberately differentiates the played vs remaining track (e.g. media seek bars) while shared UI code calls the unified getter; generic tint-inspection helpers.
Related errors
- The inactive and active ticks are different colors. Use the
- indicatorColors cannot be empty when indicatorColor is not u
- The stepSize(%s) must be 0, or a factor of the valueFrom(%s)
- valueFrom(%s) must be smaller than valueTo(%s)
- Slider value(%s) must be greater or equal to valueFrom(%s),
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/6c1f5eff5bce7e83.
Report an issue: GitHub.