{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TopAppBarDefaults

@ExperimentalMaterial3Api
public static class TopAppBarDefaults


Contains default values used for the top app bar implementations.

Summary

Public fields

static @NonNull TopAppBarDefaults

Public methods

final @NonNull TopAppBarColors

Creates a TopAppBarColors for CenterAlignedTopAppBars.

final @NonNull TopAppBarColors
@Composable
centerAlignedTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for CenterAlignedTopAppBars.

final @NonNull TopAppBarScrollBehavior
@ExperimentalMaterial3Api
@Composable
enterAlwaysScrollBehavior(
    @NonNull TopAppBarState state,
    @NonNull Function0<@NonNull Boolean> canScroll,
    AnimationSpec<@NonNull Float> snapAnimationSpec,
    DecayAnimationSpec<@NonNull Float> flingAnimationSpec
)

Returns a TopAppBarScrollBehavior.

final @NonNull TopAppBarScrollBehavior
@ExperimentalMaterial3Api
@Composable
exitUntilCollapsedScrollBehavior(
    @NonNull TopAppBarState state,
    @NonNull Function0<@NonNull Boolean> canScroll,
    AnimationSpec<@NonNull Float> snapAnimationSpec,
    DecayAnimationSpec<@NonNull Float> flingAnimationSpec
)

Returns a TopAppBarScrollBehavior that adjusts its properties to affect the colors and height of the top app bar.

final @NonNull WindowInsets

Default insets to be used and consumed by the top app bars

final @NonNull TopAppBarColors

Creates a TopAppBarColors for LargeTopAppBars.

final @NonNull TopAppBarColors
@Composable
largeTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for LargeTopAppBars.

final @NonNull TopAppBarColors

Creates a TopAppBarColors for MediumTopAppBars.

final @NonNull TopAppBarColors
@Composable
mediumTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for MediumTopAppBars.

final @NonNull TopAppBarScrollBehavior

Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly.

final @NonNull TopAppBarColors
@Composable
smallTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

This method is deprecated. Use topAppBarColors instead.

final @NonNull TopAppBarColors

Creates a TopAppBarColors for small TopAppBar.

final @NonNull TopAppBarColors
@Composable
topAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for small TopAppBar.

Public fields

INSTANCE

public static @NonNull TopAppBarDefaults INSTANCE

Public methods

centerAlignedTopAppBarColors

@Composable
public final @NonNull TopAppBarColors centerAlignedTopAppBarColors()

Creates a TopAppBarColors for CenterAlignedTopAppBars. The default implementation animates between the provided colors according to the Material Design specification.

centerAlignedTopAppBarColors

@Composable
public final @NonNull TopAppBarColors centerAlignedTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for CenterAlignedTopAppBars. The default implementation animates between the provided colors according to the Material Design specification.

Parameters
@NonNull Color containerColor

the container color

@NonNull Color scrolledContainerColor

the container color when content is scrolled behind it

@NonNull Color navigationIconContentColor

the content color used for the navigation icon

@NonNull Color titleContentColor

the content color used for the title

@NonNull Color actionIconContentColor

the content color used for actions

Returns
@NonNull TopAppBarColors

the resulting TopAppBarColors used for the top app bar

enterAlwaysScrollBehavior

@ExperimentalMaterial3Api
@Composable
public final @NonNull TopAppBarScrollBehavior enterAlwaysScrollBehavior(
    @NonNull TopAppBarState state,
    @NonNull Function0<@NonNull Boolean> canScroll,
    AnimationSpec<@NonNull Float> snapAnimationSpec,
    DecayAnimationSpec<@NonNull Float> flingAnimationSpec
)

Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.

Parameters
@NonNull TopAppBarState state

the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions.

@NonNull Function0<@NonNull Boolean> canScroll

a callback used to determine whether scroll events are to be handled by this EnterAlwaysScrollBehavior

AnimationSpec<@NonNull Float> snapAnimationSpec

an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position

DecayAnimationSpec<@NonNull Float> flingAnimationSpec

an optional DecayAnimationSpec that defined how to fling the top app bar when the user flings the app bar itself, or the content below it

exitUntilCollapsedScrollBehavior

@ExperimentalMaterial3Api
@Composable
public final @NonNull TopAppBarScrollBehavior exitUntilCollapsedScrollBehavior(
    @NonNull TopAppBarState state,
    @NonNull Function0<@NonNull Boolean> canScroll,
    AnimationSpec<@NonNull Float> snapAnimationSpec,
    DecayAnimationSpec<@NonNull Float> flingAnimationSpec
)

Returns a TopAppBarScrollBehavior that adjusts its properties to affect the colors and height of the top app bar.

A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the nested content is pulled up, and will expand back the collapsed area when the content is pulled all the way down.

Parameters
@NonNull TopAppBarState state

the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions.

@NonNull Function0<@NonNull Boolean> canScroll

a callback used to determine whether scroll events are to be handled by this ExitUntilCollapsedScrollBehavior

AnimationSpec<@NonNull Float> snapAnimationSpec

an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position

DecayAnimationSpec<@NonNull Float> flingAnimationSpec

an optional DecayAnimationSpec that defined how to fling the top app bar when the user flings the app bar itself, or the content below it

getWindowInsets

@Composable
public final @NonNull WindowInsets getWindowInsets()

Default insets to be used and consumed by the top app bars

largeTopAppBarColors

@Composable
public final @NonNull TopAppBarColors largeTopAppBarColors()

Creates a TopAppBarColors for LargeTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.

largeTopAppBarColors

@Composable
public final @NonNull TopAppBarColors largeTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for LargeTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.

Parameters
@NonNull Color containerColor

the container color

@NonNull Color scrolledContainerColor

the container color when content is scrolled behind it

@NonNull Color navigationIconContentColor

the content color used for the navigation icon

@NonNull Color titleContentColor

the content color used for the title

@NonNull Color actionIconContentColor

the content color used for actions

Returns
@NonNull TopAppBarColors

the resulting TopAppBarColors used for the top app bar

mediumTopAppBarColors

@Composable
public final @NonNull TopAppBarColors mediumTopAppBarColors()

Creates a TopAppBarColors for MediumTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.

mediumTopAppBarColors

@Composable
public final @NonNull TopAppBarColors mediumTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for MediumTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.

Parameters
@NonNull Color containerColor

the container color

@NonNull Color scrolledContainerColor

the container color when content is scrolled behind it

@NonNull Color navigationIconContentColor

the content color used for the navigation icon

@NonNull Color titleContentColor

the content color used for the title

@NonNull Color actionIconContentColor

the content color used for actions

Returns
@NonNull TopAppBarColors

the resulting TopAppBarColors used for the top app bar

pinnedScrollBehavior

@ExperimentalMaterial3Api
@Composable
public final @NonNull TopAppBarScrollBehavior pinnedScrollBehavior(
    @NonNull TopAppBarState state,
    @NonNull Function0<@NonNull Boolean> canScroll
)

Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly.

Parameters
@NonNull TopAppBarState state

the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions.

@NonNull Function0<@NonNull Boolean> canScroll

a callback used to determine whether scroll events are to be handled by this pinned TopAppBarScrollBehavior

smallTopAppBarColors

@Composable
public final @NonNull TopAppBarColors smallTopAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for small TopAppBars. The default implementation animates between the provided colors according to the Material Design specification.

use topAppBarColors instead

Parameters
@NonNull Color containerColor

the container color

@NonNull Color scrolledContainerColor

the container color when content is scrolled behind it

@NonNull Color navigationIconContentColor

the content color used for the navigation icon

@NonNull Color titleContentColor

the content color used for the title

@NonNull Color actionIconContentColor

the content color used for actions

Returns
@NonNull TopAppBarColors

the resulting TopAppBarColors used for the top app bar

topAppBarColors

@Composable
public final @NonNull TopAppBarColors topAppBarColors()

Creates a TopAppBarColors for small TopAppBar. The default implementation animates between the provided colors according to the Material Design specification.

topAppBarColors

@Composable
public final @NonNull TopAppBarColors topAppBarColors(
    @NonNull Color containerColor,
    @NonNull Color scrolledContainerColor,
    @NonNull Color navigationIconContentColor,
    @NonNull Color titleContentColor,
    @NonNull Color actionIconContentColor
)

Creates a TopAppBarColors for small TopAppBar. The default implementation animates between the provided colors according to the Material Design specification.

Parameters
@NonNull Color containerColor

the container color

@NonNull Color scrolledContainerColor

the container color when content is scrolled behind it

@NonNull Color navigationIconContentColor

the content color used for the navigation icon

@NonNull Color titleContentColor

the content color used for the title

@NonNull Color actionIconContentColor

the content color used for actions

Returns
@NonNull TopAppBarColors

the resulting TopAppBarColors used for the top app bar