Compose Component

MediumExtendedFloatingActionButton

Material Design medium extended floating action button Extended FABs help people take primary actions.

MediumExtendedFloatingActionButton social preview

MediumExtendedFloatingActionButtonTextSample

@Preview
@Sampled
@Composable
fun MediumExtendedFloatingActionButtonTextSample() {
    MediumExtendedFloatingActionButton(onClick = { /* do something */ }) {
        Text(text = "Medium Extended FAB")
    }
}

MediumExtendedFloatingActionButtonSample

@Preview
@Sampled
@Composable
fun MediumExtendedFloatingActionButtonSample() {
    MediumExtendedFloatingActionButton(
        onClick = { /* do something */ },
        icon = {
            Icon(
                Icons.Filled.Add,
                "Localized description",
                modifier = Modifier.size(FloatingActionButtonDefaults.MediumIconSize),
            )
        },
        text = { Text(text = "Medium Extended FAB") },
    )
}

MediumAnimatedExtendedFloatingActionButtonSample

@Preview
@Sampled
@Composable
fun MediumAnimatedExtendedFloatingActionButtonSample() {
    val listState = rememberLazyListState()
    // The FAB is initially expanded. Once the first visible item is past the first item we
    // collapse the FAB. We use a remembered derived state to minimize unnecessary compositions.
    val expandedFab by remember { derivedStateOf { listState.firstVisibleItemIndex == 0 } }
    Scaffold(
        floatingActionButton = {
            // A collapsed FAB should have a tooltip associated with it.
            TooltipBox(
                positionProvider =
                    TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
                tooltip = {
                    if (!expandedFab) {
                        PlainTooltip(
                            modifier =
                                Modifier.semantics {
                                    // TODO(b/496338253): Remove this modifier once bug where
                                    //  tooltip text is not announced by a11y screen readers is
                                    //  resolved.
                                    liveRegion = LiveRegionMode.Assertive
                                    paneTitle = "Localized description"
                                }
                        ) {
                            Text("Localized description")
                        }
                    }
                },
                state = rememberTooltipState(),
            ) {
                MediumExtendedFloatingActionButton(
                    onClick = { /* do something */ },
                    expanded = expandedFab,
                    icon = {
                        Icon(
                            Icons.Filled.Add,
                            "Localized Description",
                            modifier = Modifier.size(FloatingActionButtonDefaults.MediumIconSize),
                        )
                    },
                    text = { Text(text = "Medium Extended FAB") },
                )
            }
        },
        floatingActionButtonPosition = FabPosition.End,
    ) {
        LazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
            for (index in 0 until 100) {
                item { Text(text = "List item - $index", modifier = Modifier.padding(24.dp)) }
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: