JetpackIconToggleButton

fun JetpackIconToggleButton(checked: Boolean, onCheckedChange: (Boolean) -> Unit, icon: @Composable () -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, checkedIcon: @Composable () -> Unit = icon)

Jetpack toggle button with icon and checked icon content slots. Wraps Material 3 FilledIconToggleButton.

A filled icon button that toggles between two states with different icons. Uses primary container color when checked. Common use cases include favorites, bookmarks, or visibility toggles.

Features:

  • Automatic icon switching between checked/unchecked states

  • Filled background with rounded shape

  • Primary container color when checked, transparent when unchecked

  • Disabled state support with reduced alpha

Usage Example:

var isFavorite by remember { mutableStateOf(false) }

JetpackIconToggleButton(
checked = isFavorite,
onCheckedChange = { isFavorite = it },
icon = {
Icon(
imageVector = Icons.Default.FavoriteBorder,
contentDescription = "Add to favorites"
)
},
checkedIcon = {
Icon(
imageVector = Icons.Default.Favorite,
contentDescription = "Remove from favorites"
)
}
)

When to use:

  • Binary toggle actions (favorite/unfavorite, bookmark/unbookmark)

  • Visibility toggles (show/hide password, expand/collapse)

  • State indicators that can be toggled

Parameters

checked

Whether the toggle button is currently checked.

onCheckedChange

Called when the user clicks the toggle button and toggles checked.

icon

The icon content to show when unchecked.

modifier

Modifier to be applied to the toggle button.

enabled

Controls the enabled state of the toggle button. When false, this toggle button will not be clickable and will appear disabled to accessibility services.

checkedIcon

The icon content to show when checked. Defaults to icon if not provided.