Colton Idle
03/27/2025, 6:47 PMColton Idle
03/27/2025, 6:48 PMMaterialTheme(colorScheme = lightColorScheme(primary = Color(0xFF89CFF0))) {
Switch(
checked = isChecked,
onCheckedChange = { isChecked = it }
)
}
David Perez
03/27/2025, 7:03 PMSwitchColors(
checkedThumbColor = fromToken(SwitchTokens.SelectedHandleColor),
checkedTrackColor = fromToken(SwitchTokens.SelectedTrackColor),
checkedBorderColor = Color.Transparent,
checkedIconColor = fromToken(SwitchTokens.SelectedIconColor),
uncheckedThumbColor = fromToken(SwitchTokens.UnselectedHandleColor),
uncheckedTrackColor = fromToken(SwitchTokens.UnselectedTrackColor),
uncheckedBorderColor =
fromToken(SwitchTokens.UnselectedFocusTrackOutlineColor),
uncheckedIconColor = fromToken(SwitchTokens.UnselectedIconColor),
disabledCheckedThumbColor =
fromToken(SwitchTokens.DisabledSelectedHandleColor)
.copy(alpha = SwitchTokens.DisabledSelectedHandleOpacity)
.compositeOver(surface),
disabledCheckedTrackColor =
fromToken(SwitchTokens.DisabledSelectedTrackColor)
.copy(alpha = SwitchTokens.DisabledTrackOpacity)
.compositeOver(surface),
disabledCheckedBorderColor = Color.Transparent,
disabledCheckedIconColor =
fromToken(SwitchTokens.DisabledSelectedIconColor)
.copy(alpha = SwitchTokens.DisabledSelectedIconOpacity)
.compositeOver(surface),
disabledUncheckedThumbColor =
fromToken(SwitchTokens.DisabledUnselectedHandleColor)
.copy(alpha = SwitchTokens.DisabledUnselectedHandleOpacity)
.compositeOver(surface),
disabledUncheckedTrackColor =
fromToken(SwitchTokens.DisabledUnselectedTrackColor)
.copy(alpha = SwitchTokens.DisabledTrackOpacity)
.compositeOver(surface),
disabledUncheckedBorderColor =
fromToken(SwitchTokens.DisabledUnselectedTrackOutlineColor)
.copy(alpha = SwitchTokens.DisabledTrackOpacity)
.compositeOver(surface),
disabledUncheckedIconColor =
fromToken(SwitchTokens.DisabledUnselectedIconColor)
.copy(alpha = SwitchTokens.DisabledUnselectedIconOpacity)
.compositeOver(surface),
)
francisco
03/27/2025, 7:03 PMSwitch
has a colors
property that we use at our company to “theme” the switch.
I think the approach you shared doesn’t take into account light/dark/adaptive themes?
I think what i would do is wrap the material 3 switch and set your colors with the color property:
Switch(
checked = checked,
enabled = enabled,
onCheckedChange = onCheckedChange,
thumbContent = thumbContent,
colors = switchColors(),
)
then somewhere:
@Composable
private fun switchColors() = SwitchDefaults.colors(
checkedThumbColor = PedalTheme.colors.interactive_contrast_02,
checkedTrackColor = PedalTheme.colors.interactive_01,
checkedBorderColor = PedalTheme.colors.interactive_01,
checkedIconColor = PedalTheme.colors.interactive_contrast_01,
uncheckedThumbColor = PedalTheme.colors.interactive_02,
uncheckedTrackColor = PedalTheme.colors.surface_03,
uncheckedBorderColor = PedalTheme.colors.interactive_stroke_02,
)
David Perez
03/27/2025, 7:04 PMprimary
is used for the track colorsfrancisco
03/27/2025, 7:04 PMcheckedTrackColor
francisco
03/27/2025, 7:05 PMDavid Perez
03/27/2025, 7:05 PMColton Idle
03/27/2025, 7:11 PMDavid Perez
03/27/2025, 7:13 PMDavid Perez
03/27/2025, 7:15 PMval SelectedFocusTrackColor = ColorSchemeKeyTokens.Primary
val DisabledSelectedTrackColor = ColorSchemeKeyTokens.OnSurface
val DisabledUnselectedTrackColor = ColorSchemeKeyTokens.SurfaceContainerHighest
val UnselectedTrackColor = ColorSchemeKeyTokens.SurfaceContainerHighest
Colton Idle
03/27/2025, 7:15 PMColton Idle
03/27/2025, 7:15 PMColton Idle
03/27/2025, 7:15 PMDavid Perez
03/27/2025, 7:17 PMDavid Perez
03/27/2025, 7:18 PMColton Idle
03/27/2025, 7:23 PMColton Idle
03/27/2025, 7:24 PMMaterialTheme(
colorScheme = lightColorScheme(
primary = Color(0xFF89CFF0),
surfaceContainerHighest = Color.Transparent,
)
) {
Colton Idle
03/27/2025, 7:24 PMDavid Perez
03/27/2025, 7:31 PMDavid Perez
03/27/2025, 7:33 PMColton Idle
03/27/2025, 7:41 PMColton Idle
03/27/2025, 7:41 PMColton Idle
03/27/2025, 7:42 PMColton Idle
03/27/2025, 7:46 PMColton Idle
03/27/2025, 7:47 PMDavid Perez
03/27/2025, 7:49 PMDavid Perez
03/27/2025, 7:49 PMfromToken(SwitchTokens.DisabledUnselectedIconColor)
.copy(alpha = SwitchTokens.DisabledUnselectedIconOpacity)
.compositeOver(surface),
David Perez
03/27/2025, 7:50 PMDavid Perez
03/27/2025, 7:50 PMColton Idle
03/27/2025, 7:52 PMMaterialTheme(
colorScheme = MaterialTheme.colorScheme.copy(
primary = Color(0xFF89CFF0)
)
)
{
Switch(
checked = !isChecked,
onCheckedChange = { isChecked = it }
)
Switch(
checked = isChecked,
onCheckedChange = { isChecked = it }
)
}
Colton Idle
03/27/2025, 7:52 PMColton Idle
03/27/2025, 7:56 PMDavid Perez
03/27/2025, 8:00 PMColton Idle
03/27/2025, 8:19 PMLouis Pullen-Freilich [G]
03/27/2025, 9:36 PMLouis Pullen-Freilich [G]
03/27/2025, 9:37 PMandrew
03/28/2025, 2:36 AMandrew
03/28/2025, 2:36 AMandrew
03/28/2025, 2:36 AMColton Idle
03/28/2025, 4:12 AMdorche
03/28/2025, 9:59 AMsurfaceTint
in lightColorScheme()
. A step further actually - I'd make sure you provide values for all ..surface..
colours where you set up your Theme. Then you can use .copy()
like you've done.
Not suggesting this is the best approach as Louis will know better here but just wanted to clear up why you get the purple tint.Colton Idle
03/28/2025, 2:00 PMLouis Pullen-Freilich [G]
03/28/2025, 4:42 PMColton Idle
03/28/2025, 5:46 PMLouis Pullen-Freilich [G]
03/28/2025, 5:49 PMColton Idle
03/28/2025, 5:53 PM