androidx.compose.material3

TopAppBar

Composable function

A top app bar shows the title of the screen, a navigation button on the left, and actions on the right. Put it in the topBar slot of a Scaffold.

Title, back button and actions
Title, back button and actions
TopAppBar(
    title = { Text("Inbox") },
    navigationIcon = {
        IconButton(onClick = {}) { Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back") }
    },
    actions = {
        IconButton(onClick = {}) { Icon(Icons.Filled.Search, "Search") }
        IconButton(onClick = {}) { Icon(Icons.Filled.MoreVert, "More") }
    },
    modifier = Modifier.width(360.dp),
)

There are four basic types. Medium and large bars start tall and can shrink to the small size while the user scrolls. See Top app bar types.

Small, center-aligned, medium and large
Small, center-aligned, medium and large
// The outline only shows the size of each bar. Bars have the page color.
val outline = Modifier.border(1.dp, MaterialTheme.colorScheme.outlineVariant)
Column(Modifier.width(360.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
    TopAppBar(title = { Text("Small") }, modifier = outline)
    CenterAlignedTopAppBar(title = { Text("Center-aligned") }, modifier = outline)
    MediumTopAppBar(title = { Text("Medium") }, modifier = outline)
    LargeTopAppBar(title = { Text("Large") }, modifier = outline)
}

Expressive adds flexible medium and large bars, with an optional subtitle and centered 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),
)

Basic

A title, with optional navigation icon and actions.

@Composable
fun TopAppBar(
    title: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    navigationIcon: @Composable () -> Unit = {},
    actions: @Composable RowScope.() -> Unit = {},
    expandedHeight: Dp = TopAppBarDefaults.TopAppBarExpandedHeight,
    windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
    colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors(),
    scrollBehavior: TopAppBarScrollBehavior? = null,
    contentPadding: PaddingValues = TopAppBarDefaults.ContentPadding,
)

title: @Composable () -> UnitRequired

The title of the screen. Usually one Text. Long titles are cut off with "…".

modifier: ModifierOptional

Default: Modifier

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

navigationIcon: @Composable () -> UnitOptional

Default: {}

A button at the start of the bar, usually back or menu. Use an IconButton.

actions: @Composable RowScope.() -> UnitOptional

Default: {}

Buttons at the end of the bar. Use IconButtons. Put rare actions in an overflow menu behind a "more" icon. Items are placed in a Row.

expandedHeight: DpOptional

Default: TopAppBarDefaults.TopAppBarExpandedHeight

The height of the bar. For medium and large bars, the height before shrinking.

windowInsets: WindowInsetsOptional

Default: TopAppBarDefaults.windowInsets

Space kept free for system bars, like the status bar on phones. The default is usually right.

colors: TopAppBarColorsOptional

Default: TopAppBarDefaults.topAppBarColors()

Sets the background, title and icon colors, and the background while content scrolls under the bar. Make one with TopAppBarDefaults.topAppBarColors.

Colored bar
Colored bar
TopAppBar(
    title = { Text("Settings") },
    colors = TopAppBarDefaults.topAppBarColors(
        containerColor = MaterialTheme.colorScheme.primaryContainer,
        titleContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
    ),
    modifier = Modifier.width(360.dp),
)

scrollBehavior: TopAppBarScrollBehavior?Optional

Default: null

How the bar reacts when the content scrolls. Default: it does not move. Get one from TopAppBarDefaults:

  • pinnedScrollBehavior(): stays put, changes color.
  • enterAlwaysScrollBehavior(): hides when scrolling down, comes back when scrolling up.
  • exitUntilCollapsedScrollBehavior(): medium and large bars shrink to the small size.

You must also connect the scrolling content: add Modifier.nestedScroll(scrollBehavior.nestedScrollConnection) to the Scaffold.

contentPadding: PaddingValuesOptionalSince 1.10

Default: TopAppBarDefaults.ContentPadding

Space between the edge of the bar and its content.

With subtitleExperimental

Adds a subtitle below the title.

@Composable
fun TopAppBar(
    title: @Composable () -> Unit,
    subtitle: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    navigationIcon: @Composable () -> Unit = {},
    actions: @Composable RowScope.() -> Unit = {},
    titleHorizontalAlignment: Alignment.Horizontal = Alignment.Start,
    expandedHeight: Dp = TopAppBarDefaults.TopAppBarExpandedHeight,
    windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
    colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors(),
    scrollBehavior: TopAppBarScrollBehavior? = null,
    contentPadding: PaddingValues = TopAppBarDefaults.ContentPadding,
)

subtitle: @Composable () -> UnitRequiredSince 1.10

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),
)

titleHorizontalAlignment: Alignment.HorizontalOptionalSince 1.10

Same as above: title, modifier, navigationIcon, actions, expandedHeight, windowInsets, colors, scrollBehavior, contentPadding.

Top app bar types

See also