Perfect. Is there any way to change the secondaryLabel depending on the checked state?
- User
Perfect. Is there any way to change the secondaryLabel depending on the checked state?
Assistant
Yes! You can conditionally change the
secondaryLabelbased on the checked state. Here's how:ToggleChip( modifier = Modifier.fillMaxWidth(), label = { Text("Brightness Mode") }, secondaryLabel = { Text(if (autoBrightness) "Automatic" else "Manual") }, onCheckedChange = { isChecked -> val newMode = if (isChecked) { Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC } else { Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL } Settings.System.putInt( contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, newMode ) autoBrightness = isChecked }, checked = autoBrightness, toggleControl = { Switch(checked = autoBrightness) }, )The key change is in the
secondaryLabel:secondaryLabel = { Text(if (autoBrightness) "Automatic" else "Manual") }Since
autoBrightnessis now a Compose state variable, any change to it will trigger a recomposition and update the secondary label text accordingly. When the toggle is on, it will show "Automatic", and when it's off, it will show "Manual".
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.