Created
June 19, 2025 09:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) | |
, | |
) | |
} | |
}, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://coolors.co/461220-ebebd3-f4d35e-e99a48-e37d3d-e06f37-dd6031-6184d8
https://udemy.com/course/jetpack-compose-android-app-development-course-with-jetpack/learn/lecture/39461490#overview