androidx.compose.material3

MediumFlexibleTopAppBarSince 1.10Experimental

Composable function

One of the top app bar types. It works like TopAppBar. Only the parameters that differ are described here.

An Expressive medium bar. It can show a subtitle and center the title.

A medium flexible bar with subtitleExpressive theme
A medium flexible bar with subtitle
MediumFlexibleTopAppBar(
    title = { Text("Photos") },
    subtitle = { Text("1,204 items") },
    navigationIcon = {
        IconButton(onClick = {}) { Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back") }
    },
    // The outline only shows the size of the bar.
    modifier = Modifier.width(360.dp).border(1.dp, MaterialTheme.colorScheme.outlineVariant),
)

ParametersExperimental

@Composable
fun MediumFlexibleTopAppBar(
    title: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    subtitle: (@Composable () -> Unit)? = null,
    navigationIcon: @Composable () -> Unit = {},
    actions: @Composable RowScope.() -> Unit = {},
    titleHorizontalAlignment: Alignment.Horizontal = Alignment.Start,
    collapsedHeight: Dp = TopAppBarDefaults.MediumAppBarCollapsedHeight,
    expandedHeight: Dp = if (subtitle != null) { TopAppBarDefaults.MediumFlexibleAppBarWithSubtitleExpandedHeight } else { TopAppBarDefaults.MediumFlexibleAppBarWithoutSubtitleExpandedHeight },
    windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
    colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors(),
    scrollBehavior: TopAppBarScrollBehavior? = null,
)

subtitle: (@Composable () -> Unit)?Optional

Default: null

A second, smaller line under the title.

Title and subtitle
Title and subtitle
TopAppBar(
    title = { Text("Trip to Lisbon") },
    subtitle = { Text("3 nights") },
    navigationIcon = {
        IconButton(onClick = {}) { Icon(Icons.Filled.Menu, "Menu") }
    },
    modifier = Modifier.width(360.dp),
)

collapsedHeight: DpOptional

Default: TopAppBarDefaults.MediumAppBarCollapsedHeight

The height of a medium or large bar after it shrinks.

Defaults that differ from TopAppBar:

Same as in TopAppBar: title, modifier, navigationIcon, actions, titleHorizontalAlignment, expandedHeight, windowInsets, colors, scrollBehavior.

Top app bar types

See also