androidx.compose.material3

ExtendedFloatingActionButton

Composable function

One of the fab types. It works like FloatingActionButton. Only the parameters that differ are described here.

A FAB with a text label. Set expanded to false to show only the icon, for example while the user scrolls.

Extended, with icon and text
Extended, with icon and text
ExtendedFloatingActionButton(
    onClick = {},
    icon = { Icon(Icons.Filled.Edit, contentDescription = null) },
    text = { Text("Compose") },
)

With content

You place the icon and text yourself.

@Composable
fun ExtendedFloatingActionButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    shape: Shape = FloatingActionButtonDefaults.extendedFabShape,
    containerColor: Color = FloatingActionButtonDefaults.containerColor,
    contentColor: Color = contentColorFor(containerColor),
    elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),
    interactionSource: MutableInteractionSource? = null,
    content: @Composable RowScope.() -> Unit,
)

content: @Composable RowScope.() -> UnitRequired

What the FAB shows. Usually one Icon with a contentDescription, because there is no text to explain it. On medium and large FABs, size the icon with FloatingActionButtonDefaults.MediumIconSize or LargeIconSize.

Defaults that differ from FloatingActionButton:

Same as in FloatingActionButton: onClick, modifier, shape, containerColor, contentColor, elevation, interactionSource.

Icon and text

Takes icon and text separately, and can collapse to the icon.

@Composable
fun ExtendedFloatingActionButton(
    text: @Composable () -> Unit,
    icon: @Composable () -> Unit,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    expanded: Boolean = true,
    shape: Shape = FloatingActionButtonDefaults.extendedFabShape,
    containerColor: Color = FloatingActionButtonDefaults.containerColor,
    contentColor: Color = contentColorFor(containerColor),
    elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),
    interactionSource: MutableInteractionSource? = null,
)

text: @Composable () -> UnitRequired

The label of an extended FAB. Hidden when expanded is false.

Extended, with icon and text
Extended, with icon and text
ExtendedFloatingActionButton(
    onClick = {},
    icon = { Icon(Icons.Filled.Edit, contentDescription = null) },
    text = { Text("Compose") },
)

icon: @Composable () -> UnitRequired

The icon of an extended FAB.

expanded: BooleanOptional

Default: true

Shows or hides the text. Set it to false while the user scrolls down, to make the FAB small. The change is animated.

Extended, collapsed to the icon
Extended, collapsed to the icon
ExtendedFloatingActionButton(
    onClick = {},
    expanded = false,
    icon = { Icon(Icons.Filled.Edit, contentDescription = "Compose") },
    text = { Text("Compose") },
)

Defaults that differ from FloatingActionButton:

Same as in FloatingActionButton: onClick, modifier, shape, containerColor, contentColor, elevation, interactionSource.

FAB types

See also