androidx.compose.material3

FloatingActionButton

Composable function

A floating action button (FAB) shows the most important action on a screen, like "Compose" or "Add". Use one per screen at most. It usually sits in the bottom end corner, in the floatingActionButton slot of a Scaffold.

A floating action button
A floating action button
FloatingActionButton(onClick = {}) {
    Icon(Icons.Filled.Add, contentDescription = "Add")
}

FABs come in four sizes, plus an extended version with text. See FAB types.

Small, default, medium and large
Small, default, medium and large
Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically) {
    SmallFloatingActionButton(onClick = {}) { Icon(Icons.Filled.Add, "Add") }
    FloatingActionButton(onClick = {}) { Icon(Icons.Filled.Add, "Add") }
    MediumFloatingActionButton(onClick = {}) {
        Icon(Icons.Filled.Add, "Add", Modifier.size(FloatingActionButtonDefaults.MediumIconSize))
    }
    LargeFloatingActionButton(onClick = {}) {
        Icon(Icons.Filled.Add, "Add", Modifier.size(FloatingActionButtonDefaults.LargeIconSize))
    }
}

Expressive adds small, medium and large extended FABs. They take the same parameters as the extended FAB.

Parameters

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

onClick: () -> UnitRequired

Called when the FAB is clicked.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position of the FAB. See the Modifier guide.

shape: ShapeOptional

Default: FloatingActionButtonDefaults.shape

Sets the outline. Each size has its own default in FloatingActionButtonDefaults. See the Shapes guide.

containerColor: ColorOptional

Default: FloatingActionButtonDefaults.containerColor

The background color. Default: the theme's primaryContainer.

Tertiary container color
Tertiary container color
FloatingActionButton(
    onClick = {},
    containerColor = MaterialTheme.colorScheme.tertiaryContainer,
) {
    Icon(Icons.Filled.Add, contentDescription = "Add")
}

contentColor: ColorOptional

Default: contentColorFor(containerColor)

The icon and text color. Default: the matching "on" color for containerColor, from contentColorFor.

elevation: FloatingActionButtonElevationOptional

Default: FloatingActionButtonDefaults.elevation()

Sets the shadow height. Use FloatingActionButtonDefaults.loweredElevation when the FAB sits inside a bar or should not float.

No shadow
No shadow
FloatingActionButton(
    onClick = {},
    elevation = FloatingActionButtonDefaults.loweredElevation(),
) {
    Icon(Icons.Filled.Add, contentDescription = "Add")
}

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

content: @Composable () -> 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.

FAB types

See also