IconToggleButtonDefaults

object IconToggleButtonDefaults


Contains the default values used by IconToggleButton.

Summary

Public functions

Shape
@Composable
animatedShape(
    interactionSource: InteractionSource,
    shape: CornerBasedShape,
    pressedShape: CornerBasedShape
)

Creates a Shape with a animation between two CornerBasedShapes based on the pressed state.

Dp
iconSizeFor(buttonSize: Dp)

Recommended icon size for a given icon toggle button size.

IconToggleButtonColors

Creates an IconToggleButtonColors for a IconToggleButton

IconToggleButtonColors
@Composable
iconToggleButtonColors(
    checkedContainerColor: Color,
    checkedContentColor: Color,
    uncheckedContainerColor: Color,
    uncheckedContentColor: Color,
    disabledCheckedContainerColor: Color,
    disabledCheckedContentColor: Color,
    disabledUncheckedContainerColor: Color,
    disabledUncheckedContentColor: Color
)

Creates a IconToggleButtonColors for a IconToggleButton

Shape
@Composable
variantAnimatedShape(
    interactionSource: InteractionSource,
    checked: Boolean,
    uncheckedCornerSize: CornerSize,
    checkedCornerSize: CornerSize,
    pressedCornerSize: CornerSize,
    onPressAnimationSpec: FiniteAnimationSpec<Float>,
    onReleaseAnimationSpec: FiniteAnimationSpec<Float>
)

Creates a Shape with an animation between three CornerSizes based on the pressed state and checked/unchecked.

Public properties

CornerSize

The recommended size for a Checked button when animated.

Dp

The default size applied for icon toggle buttons.

Dp

The default size of an icon when used inside an icon toggle button of size DefaultButtonSize.

Dp

The recommended size for an extra icon large toggle button.

Dp

The size of an icon when used inside an icon toggle button with size ExtraLargeButtonSize.

Dp

The recommended size for a large icon toggle button.

Dp

The size of an icon when used inside an icon toggle button with size LargeButtonSize.

CornerSize

The recommended size for a Pressed button when animated.

Dp

The recommended size for a small button.

Dp

The recommended size of an icon when used inside an icon toggle button with size SmallButtonSize.

CornerSize

The recommended size for an Unchecked button when animated.

CornerBasedShape

Recommended pressed Shape for IconToggleButton.

RoundedCornerShape

Recommended Shape for IconToggleButton.

Public functions

animatedShape

Added in 1.0.0-alpha26
@Composable
fun animatedShape(
    interactionSource: InteractionSource,
    shape: CornerBasedShape = IconToggleButtonDefaults.shape,
    pressedShape: CornerBasedShape = IconToggleButtonDefaults.pressedShape
): Shape

Creates a Shape with a animation between two CornerBasedShapes based on the pressed state.

A simple icon toggle button using the default colors, animated when pressed.

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.IconButtonDefaults
import androidx.wear.compose.material3.IconToggleButton

val interactionSource = remember { MutableInteractionSource() }
var checked by remember { mutableStateOf(true) }
IconToggleButton(
    checked = checked,
    onCheckedChange = { checked = !checked },
    interactionSource = interactionSource,
    shape =
        IconButtonDefaults.animatedShape(
            interactionSource = interactionSource,
        ),
) {
    Icon(imageVector = Icons.Filled.Favorite, contentDescription = "Favorite icon")
}
Parameters
interactionSource: InteractionSource

the interaction source applied to the Button.

shape: CornerBasedShape = IconToggleButtonDefaults.shape

The normal shape of the IconToggleButton.

pressedShape: CornerBasedShape = IconToggleButtonDefaults.pressedShape

The pressed shape of the IconToggleButton.

iconSizeFor

fun iconSizeFor(buttonSize: Dp): Dp

Recommended icon size for a given icon toggle button size.

Ensures that the minimum recommended icon size is applied.

Examples: for size SmallButtonSize, returns SmallIconSize, for size ExtraLargeButtonSize returns ExtraLargeIconSize.

Parameters
buttonSize: Dp

The size of the icon toggle button

iconToggleButtonColors

Added in 1.0.0-alpha26
@Composable
fun iconToggleButtonColors(): IconToggleButtonColors

Creates an IconToggleButtonColors for a IconToggleButton

  • by default, a colored background with a contrasting content color.

If the button is disabled, then the colors will have an alpha (DisabledContentAlpha and DisabledContainerAlpha) value applied.

iconToggleButtonColors

@Composable
fun iconToggleButtonColors(
    checkedContainerColor: Color = Color.Unspecified,
    checkedContentColor: Color = Color.Unspecified,
    uncheckedContainerColor: Color = Color.Unspecified,
    uncheckedContentColor: Color = Color.Unspecified,
    disabledCheckedContainerColor: Color = Color.Unspecified,
    disabledCheckedContentColor: Color = Color.Unspecified,
    disabledUncheckedContainerColor: Color = Color.Unspecified,
    disabledUncheckedContentColor: Color = Color.Unspecified
): IconToggleButtonColors

Creates a IconToggleButtonColors for a IconToggleButton

  • by default, a colored background with a contrasting content color.

If the button is disabled, then the colors will have an alpha (DisabledContentAlpha and DisabledContainerAlpha) value applied.

Parameters
checkedContainerColor: Color = Color.Unspecified

The container color of this IconToggleButton when enabled and checked

checkedContentColor: Color = Color.Unspecified

The content color of this IconToggleButton when enabled and checked

uncheckedContainerColor: Color = Color.Unspecified

The container color of this IconToggleButton when enabled and unchecked

uncheckedContentColor: Color = Color.Unspecified

The content color of this IconToggleButton when enabled and unchecked

disabledCheckedContainerColor: Color = Color.Unspecified

The container color of this IconToggleButton when checked and not enabled

disabledCheckedContentColor: Color = Color.Unspecified

The content color of this IconToggleButton when checked and not enabled

disabledUncheckedContainerColor: Color = Color.Unspecified

The container color of this IconToggleButton when unchecked and not enabled

disabledUncheckedContentColor: Color = Color.Unspecified

The content color of this IconToggleButton when unchecked and not enabled

variantAnimatedShape

Added in 1.0.0-alpha26
@Composable
fun variantAnimatedShape(
    interactionSource: InteractionSource,
    checked: Boolean,
    uncheckedCornerSize: CornerSize = UncheckedCornerSize,
    checkedCornerSize: CornerSize = CheckedCornerSize,
    pressedCornerSize: CornerSize = PressedCornerSize,
    onPressAnimationSpec: FiniteAnimationSpec<Float> = MaterialTheme.motionScheme.rememberFastSpatialSpec(),
    onReleaseAnimationSpec: FiniteAnimationSpec<Float> = MaterialTheme.motionScheme.slowSpatialSpec()
): Shape

Creates a Shape with an animation between three CornerSizes based on the pressed state and checked/unchecked.

A simple icon toggle button using the default colors, animated on Press and Check/Uncheck:

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.IconToggleButton
import androidx.wear.compose.material3.IconToggleButtonDefaults
import androidx.wear.compose.material3.samples.icons.WifiOffIcon
import androidx.wear.compose.material3.samples.icons.WifiOnIcon

val interactionSource = remember { MutableInteractionSource() }
var checked by remember { mutableStateOf(true) }
IconToggleButton(
    checked = checked,
    onCheckedChange = { checked = !checked },
    interactionSource = interactionSource,
    shape =
        IconToggleButtonDefaults.variantAnimatedShape(
            interactionSource = interactionSource,
            checked = checked
        ),
) {
    if (checked) {
        WifiOnIcon()
    } else {
        WifiOffIcon()
    }
}
Parameters
interactionSource: InteractionSource

the interaction source applied to the Button.

checked: Boolean

the current checked/unchecked state.

uncheckedCornerSize: CornerSize = UncheckedCornerSize

the size of the corner when unchecked.

checkedCornerSize: CornerSize = CheckedCornerSize

the size of the corner when checked.

pressedCornerSize: CornerSize = PressedCornerSize

the size of the corner when pressed.

onPressAnimationSpec: FiniteAnimationSpec<Float> = MaterialTheme.motionScheme.rememberFastSpatialSpec()

the spec for press animation.

onReleaseAnimationSpec: FiniteAnimationSpec<Float> = MaterialTheme.motionScheme.slowSpatialSpec()

the spec for release animation.

Public properties

CheckedCornerSize

Added in 1.0.0-alpha26
val CheckedCornerSizeCornerSize

The recommended size for a Checked button when animated.

DefaultButtonSize

Added in 1.0.0-alpha26
val DefaultButtonSizeDp

The default size applied for icon toggle buttons. It is recommended to apply this size using Modifier.touchTargetAwareSize.

DefaultIconSize

Added in 1.0.0-alpha26
val DefaultIconSizeDp

The default size of an icon when used inside an icon toggle button of size DefaultButtonSize. Use iconSizeFor to easily determine the icon size.

ExtraLargeButtonSize

Added in 1.0.0-alpha26
val ExtraLargeButtonSizeDp

The recommended size for an extra icon large toggle button. It is recommended to apply this size using Modifier.touchTargetAwareSize.

ExtraLargeIconSize

Added in 1.0.0-alpha26
val ExtraLargeIconSizeDp

The size of an icon when used inside an icon toggle button with size ExtraLargeButtonSize. Use iconSizeFor to easily determine the icon size.

LargeButtonSize

Added in 1.0.0-alpha26
val LargeButtonSizeDp

The recommended size for a large icon toggle button. It is recommended to apply this size using Modifier.touchTargetAwareSize.

LargeIconSize

Added in 1.0.0-alpha26
val LargeIconSizeDp

The size of an icon when used inside an icon toggle button with size LargeButtonSize. Use iconSizeFor to easily determine the icon size.

PressedCornerSize

Added in 1.0.0-alpha26
val PressedCornerSizeCornerSize

The recommended size for a Pressed button when animated.

SmallButtonSize

Added in 1.0.0-alpha26
val SmallButtonSizeDp

The recommended size for a small button. It is recommended to apply this size using Modifier.touchTargetAwareSize.

SmallIconSize

Added in 1.0.0-alpha26
val SmallIconSizeDp

The recommended size of an icon when used inside an icon toggle button with size SmallButtonSize. Use iconSizeFor to easily determine the icon size.

UncheckedCornerSize

Added in 1.0.0-alpha26
val UncheckedCornerSizeCornerSize

The recommended size for an Unchecked button when animated.

pressedShape

Added in 1.0.0-alpha26
val pressedShapeCornerBasedShape

Recommended pressed Shape for IconToggleButton.

shape

Added in 1.0.0-alpha26
val shapeRoundedCornerShape

Recommended Shape for IconToggleButton.