androidx.compose.material3

AppBarWithSearchSince 1.10Experimental

Composable function

One of the search bar types. It works like SearchBar. Only the parameters that differ are described here.

A top app bar with a search field in the middle and room for icons on both sides.

A search field in an app barExpressive theme
A search field in an app bar
val text = rememberTextFieldState()
val state = rememberSearchBarState()
AppBarWithSearch(
    state = state,
    inputField = {
        SearchBarDefaults.InputField(
            textFieldState = text,
            searchBarState = state,
            onSearch = {},
            placeholder = { Text("Search photos") },
        )
    },
    navigationIcon = { IconButton(onClick = {}) { Icon(Icons.Filled.Menu, "Menu") } },
    actions = { IconButton(onClick = {}) { Icon(Icons.Filled.Person, "Account") } },
    modifier = Modifier.width(400.dp),
)

ParametersExperimental

@Composable
fun AppBarWithSearch(
    state: SearchBarState,
    inputField: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    navigationIcon: @Composable (() -> Unit)? = null,
    actions: @Composable (RowScope.() -> Unit)? = null,
    shape: Shape = SearchBarDefaults.inputFieldShape,
    colors: AppBarWithSearchColors = SearchBarDefaults.appBarWithSearchColors(),
    tonalElevation: Dp = SearchBarDefaults.TonalElevation,
    shadowElevation: Dp = SearchBarDefaults.ShadowElevation,
    contentPadding: PaddingValues = SearchBarDefaults.AppBarContentPadding,
    windowInsets: WindowInsets = SearchBarDefaults.windowInsets,
    scrollBehavior: SearchBarScrollBehavior? = null,
)

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

Default: null

A button before the field in AppBarWithSearch, like back or menu.

actions: @Composable (RowScope.() -> Unit)?Optional

Default: null

Buttons after the field in AppBarWithSearch.

colors: AppBarWithSearchColorsOptional

Default: SearchBarDefaults.appBarWithSearchColors()

Sets the container and field colors. Make one with SearchBarDefaults.colors.

contentPadding: PaddingValuesOptional

Default: SearchBarDefaults.AppBarContentPadding

Space between the edge of the app bar and its content.

scrollBehavior: SearchBarScrollBehavior?Optional

Default: null

Hides AppBarWithSearch while the user scrolls.

Same as in SearchBar: state, inputField, modifier, shape, tonalElevation, shadowElevation, windowInsets.

Search bar types

See also