HorizontalFloatingToolbar

@Composable
fun HorizontalFloatingToolbar(expanded: Boolean, modifier: Modifier = Modifier, colors: FloatingToolbarColors = FloatingToolbarDefaults.standardFloatingToolbarColors(), contentPadding: PaddingValues = FloatingToolbarDefaults.ContentPadding, scrollBehavior: FloatingToolbarScrollBehavior? = null, shape: Shape = FloatingToolbarDefaults.ContainerShape, leadingContent: @Composable RowScope.() -> Unit? = null, trailingContent: @Composable RowScope.() -> Unit? = null, expandedShadowElevation: Dp = FloatingToolbarDefaults.ContainerExpandedElevation, collapsedShadowElevation: Dp = FloatingToolbarDefaults.ContainerCollapsedElevation, content: @Composable RowScope.() -> Unit)

A horizontal floating toolbar displays navigation and key actions in a Row. It can be positioned anywhere on the screen and floats over the rest of the content.

Note: This component will stay expanded to maintain the toolbar visibility for users with touch exploration services enabled (e.g., TalkBack).

Parameters

expanded

whether the FloatingToolbar is in expanded mode, i.e. showing leadingContent and trailingContent. Note that the toolbar will stay expanded in case a touch exploration service (e.g., TalkBack) is active.

modifier

the Modifier to be applied to this FloatingToolbar.

colors

the colors used for this floating toolbar. There are two predefined FloatingToolbarColors at FloatingToolbarDefaults.standardFloatingToolbarColors and FloatingToolbarDefaults.vibrantFloatingToolbarColors which you can use or modify.

contentPadding

the padding applied to the content of this FloatingToolbar.

scrollBehavior

a FloatingToolbarScrollBehavior. If null, this FloatingToolbar will not automatically react to scrolling. Note that the toolbar will not react to scrolling in case a touch exploration service (e.g., TalkBack) is active.

shape

the shape used for this FloatingToolbar.

leadingContent

the leading content of this FloatingToolbar. The default layout here is a Row, so content inside will be placed horizontally. Only showing if expanded is true.

trailingContent

the trailing content of this FloatingToolbar. The default layout here is a Row, so content inside will be placed horizontally. Only showing if expanded is true.

expandedShadowElevation

the elevation for the shadow below this floating toolbar when expanded.

collapsedShadowElevation

the elevation for the shadow below this floating toolbar when collapsed.

content

the main content of this FloatingToolbar. The default layout here is a Row, so content inside will be placed horizontally.

Samples

androidx.compose.material3.samples.ExpandableHorizontalFloatingToolbarSampleandroidx.compose.material3.samples.OverflowingHorizontalFloatingToolbarSampleandroidx.compose.material3.samples.ScrollableHorizontalFloatingToolbarSample
@Composable
fun HorizontalFloatingToolbar(expanded: Boolean, floatingActionButton: @Composable () -> Unit, modifier: Modifier = Modifier, colors: FloatingToolbarColors = FloatingToolbarDefaults.standardFloatingToolbarColors(), contentPadding: PaddingValues = FloatingToolbarDefaults.ContentPadding, scrollBehavior: FloatingToolbarScrollBehavior? = null, shape: Shape = FloatingToolbarDefaults.ContainerShape, floatingActionButtonPosition: FloatingToolbarHorizontalFabPosition = FloatingToolbarHorizontalFabPosition.End, animationSpec: FiniteAnimationSpec<Float> = FloatingToolbarDefaults.animationSpec(), expandedShadowElevation: Dp = FloatingToolbarDefaults.ContainerExpandedElevationWithFab, collapsedShadowElevation: Dp = FloatingToolbarDefaults.ContainerCollapsedElevationWithFab, content: @Composable RowScope.() -> Unit)

A floating toolbar that displays horizontally. The bar features its content within a Row, and an adjacent floating icon button. It can be positioned anywhere on the screen, floating above other content, and even in a Scaffold's floating action button slot. Its expanded flag controls the visibility of the actions with a slide animations.

Note: This component will stay expanded to maintain the toolbar visibility for users with touch exploration services enabled (e.g., TalkBack).

In case the toolbar is aligned to the right or the left of the screen, you may apply a FloatingToolbarDefaults.floatingToolbarVerticalNestedScroll Modifier to update the expanded state when scrolling occurs, as this sample shows:

Parameters

expanded

whether the floating toolbar is expanded or not. In its expanded state, the FAB and the toolbar content are organized horizontally. Otherwise, only the FAB is visible. Note that the toolbar will stay expanded in case a touch exploration service (e.g., TalkBack) is active.

floatingActionButton

a floating action button to be displayed by the toolbar. It's recommended to use a FloatingToolbarDefaults.VibrantFloatingActionButton or FloatingToolbarDefaults.StandardFloatingActionButton that is styled to match the colors. Note that the provided FAB's size is controlled by the floating toolbar and animates according to its state. In case a custom FAB is provided, make sure it's set with a Modifier.fillMaxSize to be sized correctly.

modifier

the Modifier to be applied to this floating toolbar.

colors

the colors used for this floating toolbar. There are two predefined FloatingToolbarColors at FloatingToolbarDefaults.standardFloatingToolbarColors and FloatingToolbarDefaults.vibrantFloatingToolbarColors which you can use or modify. See also floatingActionButton for more information on the right FAB to use for proper styling.

contentPadding

the padding applied to the content of this floating toolbar.

scrollBehavior

a FloatingToolbarScrollBehavior. If provided, this FloatingToolbar will automatically react to scrolling. If your toolbar is positioned along a center edge of the screen (like top or bottom center), it's best to use this scroll behavior to make the entire toolbar scroll off-screen as the user scrolls. This would prevent the FAB from appearing off-center, which may occur in this case when using the expanded flag to simply expand or collapse the toolbar. Note that the toolbar will not react to scrolling in case a touch exploration service (e.g., TalkBack) is active.

shape

the shape used for this floating toolbar content.

floatingActionButtonPosition

the position of the floating toolbar's floating action button. By default, the FAB is placed at the end of the toolbar (i.e. aligned to the right in left-to-right layout, or to the left in right-to-left layout).

animationSpec

the animation spec to use for this floating toolbar expand and collapse animation.

expandedShadowElevation

the elevation for the shadow below this floating toolbar when expanded.

collapsedShadowElevation

the elevation for the shadow below this floating toolbar when collapsed.

content

the main content of this floating toolbar. The default layout here is a Row, so content inside will be placed horizontally.

Samples

androidx.compose.material3.samples.HorizontalFloatingToolbarWithFabSampleandroidx.compose.material3.samples.CenteredHorizontalFloatingToolbarWithFabSampleandroidx.compose.material3.samples.HorizontalFloatingToolbarAsScaffoldFabSample