androidx.compose.material3

Scaffold

Composable function

A scaffold lays out a whole screen. You give it the parts, and it places them: the top bar at the top, the bottom bar at the bottom, the FAB above the bottom bar, and your content in between.

Use one Scaffold per screen.

A full screen: top bar, bottom bar and FAB
A full screen: top bar, bottom bar and FAB
var selected by remember { mutableIntStateOf(0) }
Scaffold(
    modifier = Modifier.size(360.dp, 560.dp),
    topBar = { TopAppBar(title = { Text("Photos") }) },
    bottomBar = {
        NavigationBar {
            NavigationBarItem(selected == 0, { selected = 0 }, { Icon(Icons.Filled.Home, null) }, label = { Text("Home") })
            NavigationBarItem(selected == 1, { selected = 1 }, { Icon(Icons.Filled.Favorite, null) }, label = { Text("Favorites") })
        }
    },
    floatingActionButton = {
        FloatingActionButton(onClick = {}) { Icon(Icons.Filled.Add, "Add photo") }
    },
) { innerPadding ->
    // Use innerPadding, or the content goes under the bars.
    Column(Modifier.padding(innerPadding).padding(16.dp)) {
        Text("Your photos appear here.")
    }
}

Parameters

@Composable
fun Scaffold(
    modifier: Modifier = Modifier,
    topBar: @Composable () -> Unit = {},
    bottomBar: @Composable () -> Unit = {},
    snackbarHost: @Composable () -> Unit = {},
    floatingActionButton: @Composable () -> Unit = {},
    floatingActionButtonPosition: FabPosition = FabPosition.End,
    containerColor: Color = MaterialTheme.colorScheme.background,
    contentColor: Color = contentColorFor(containerColor),
    contentWindowInsets: WindowInsets = ScaffoldDefaults.contentWindowInsets,
    content: @Composable (PaddingValues) -> Unit,
)

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position of the scaffold. See the Modifier guide. Add Modifier.nestedScroll(...) here when the top bar has a scrollBehavior.

topBar: @Composable () -> UnitOptional

Default: {}

The bar at the top. Usually a TopAppBar.

bottomBar: @Composable () -> UnitOptional

Default: {}

The bar at the bottom. Usually a NavigationBar or a BottomAppBar.

snackbarHost: @Composable () -> UnitOptional

Default: {}

Where snackbars appear. Usually SnackbarHost(snackbarHostState). Show a snackbar with snackbarHostState.showSnackbar("Saved") from a coroutine.

floatingActionButton: @Composable () -> UnitOptional

Default: {}

The main action of the screen. Usually a FloatingActionButton.

floatingActionButtonPosition: FabPositionOptional

Default: FabPosition.End

Where the FAB sits: FabPosition.End (default), Start, Center, or EndOverlay (over the bottom bar).

containerColor: ColorOptional

Default: MaterialTheme.colorScheme.background

The background color of the screen. Default: the theme's background.

contentColor: ColorOptional

Default: contentColorFor(containerColor)

The default color for text and icons in the content.

contentWindowInsets: WindowInsetsOptional

Default: ScaffoldDefaults.contentWindowInsets

Space kept free for system bars around the content. The default is usually right.

content: @Composable (PaddingValues) -> UnitRequired

The main content of the screen.

It receives PaddingValues: the space taken by the bars. Apply it with Modifier.padding(innerPadding), or your content goes under the bars. For a list, pass it as contentPadding instead, so items can scroll under the bars.

See also