Skip to content

Instantly share code, notes, and snippets.

@vaimalaviya1233
Created June 19, 2025 09:41
Show Gist options
  • Save vaimalaviya1233/58312cb2d714d4f75b7a5d6e6acb24e0 to your computer and use it in GitHub Desktop.
Save vaimalaviya1233/58312cb2d714d4f75b7a5d6e6acb24e0 to your computer and use it in GitHub Desktop.
switch composable with custom unchecked and checked colors and with custom unchecked icon
@Composable
fun SwitchWithThumbIconSample() {
var checked by remember { mutableStateOf(false) }
Switch(
modifier = Modifier.semantics { contentDescription = "Demo with icon" },
colors = SwitchDefaults.colors(
uncheckedTrackColor=Color(0xFFB71C1C),
uncheckedBorderColor = Color(239, 83, 80, 255),
uncheckedThumbColor = Color(0xFFFF9052),
uncheckedIconColor = Color(0xFFEEEEEE),
checkedTrackColor = Color(0xFFB2FF59),
checkedBorderColor = Color(102, 187, 106, 255),
checkedThumbColor = Color(0xFF134537),
checkedIconColor = Color(0xFFA9EAD2)
),
checked = checked,
onCheckedChange = { checked = it },
thumbContent = {
if (checked) {
// Icon isn't focusable, no need for content description
Icon(
imageVector = Icons.Filled.Check,
contentDescription = null,
modifier = Modifier.size(SwitchDefaults.IconSize),
)
}else{
Icon(
imageVector = Icons.Filled.Close,
contentDescription = null,
modifier = Modifier.size(SwitchDefaults.IconSize)
,
)
}
},
)
}