androidx.compose.material3
SearchBarExperimental
Composable function
A search bar is a field for searching. When the user taps it, it opens a view for suggestions and results.
In the newer form, the work is split in two:
- A collapsed
SearchBar(orAppBarWithSearchat the top of a screen) shows the field. - An expanded bar shows results:
ExpandedFullScreenSearchBaron phones,ExpandedDockedSearchBaron wider screens. Pass it the same state and field.
Both get a SearchBarState from rememberSearchBarState(). The text lives in a TextFieldState.

val text = rememberTextFieldState()
val state = rememberSearchBarState()
SearchBar(
state = state,
inputField = {
SearchBarDefaults.InputField(
textFieldState = text,
searchBarState = state,
onSearch = { /* run the search */ },
placeholder = { Text("Search photos") },
leadingIcon = { Icon(Icons.Filled.Search, contentDescription = null) },
)
},
modifier = Modifier.width(360.dp),
)
Make the field with SearchBarDefaults.InputField. Pass it the text state, the search bar state, and onSearch, which runs when the user presses the search key.
StateSince 1.9Experimental
The newer form. Takes a SearchBarState. Pair it with an expanded search bar.
@Composable
fun SearchBar(
state: SearchBarState,
inputField: @Composable () -> Unit,
modifier: Modifier = Modifier,
shape: Shape = SearchBarDefaults.inputFieldShape,
colors: SearchBarColors = SearchBarDefaults.colors(),
tonalElevation: Dp = SearchBarDefaults.TonalElevation,
shadowElevation: Dp = SearchBarDefaults.ShadowElevation,
)
state: SearchBarStateRequired
state: SearchBarStateRequiredWhether the bar is collapsed or expanded. Create it with rememberSearchBarState(). Share it between the collapsed and the expanded bar.
inputField: @Composable () -> UnitRequired
inputField: @Composable () -> UnitRequiredThe text field. Use SearchBarDefaults.InputField(...).
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. See the Modifier guide.
shape: ShapeOptional
shape: ShapeOptionalDefault: SearchBarDefaults.inputFieldShape
Sets the outline. Default: fully round.
colors: SearchBarColorsOptional
colors: SearchBarColorsOptionalDefault: SearchBarDefaults.colors()
Sets the container and field colors. Make one with SearchBarDefaults.colors.
tonalElevation: DpOptional
tonalElevation: DpOptionalDefault: SearchBarDefaults.TonalElevation
Tints the background a little toward the primary color.
shadowElevation: DpOptional
shadowElevation: DpOptionalDefault: SearchBarDefaults.ShadowElevation
The size of the shadow under the bar.
Expanded flagExperimental
The older form. Takes expanded and shows results inside itself.
@Composable
fun SearchBar(
inputField: @Composable () -> Unit,
expanded: Boolean,
onExpandedChange: (Boolean) -> Unit,
modifier: Modifier = Modifier,
shape: Shape = SearchBarDefaults.inputFieldShape,
colors: SearchBarColors = SearchBarDefaults.colors(),
tonalElevation: Dp = SearchBarDefaults.TonalElevation,
shadowElevation: Dp = SearchBarDefaults.ShadowElevation,
windowInsets: WindowInsets = SearchBarDefaults.windowInsets,
content: @Composable ColumnScope.() -> Unit,
)
expanded: BooleanRequired
expanded: BooleanRequiredWhether the older search bar is open. Pass your state here.
onExpandedChange: (Boolean) -> UnitRequired
onExpandedChange: (Boolean) -> UnitRequiredCalled when the older search bar opens or closes. Update your state here.
windowInsets: WindowInsetsOptional
windowInsets: WindowInsetsOptionalDefault: SearchBarDefaults.windowInsets
Space kept free for system bars. The default is usually right.
content: @Composable ColumnScope.() -> UnitRequired
content: @Composable ColumnScope.() -> UnitRequiredSuggestions or results, shown while the bar is expanded. Placed in a Column.
Same as above: inputField, modifier, shape, colors, tonalElevation, shadowElevation.
Search bar types
SearchBarDockedSearchBarAppBarWithSearchExpandedFullScreenSearchBarExpandedFullScreenContainedSearchBarExpandedDockedSearchBarExpandedDockedSearchBarWithGap
See also
SearchBarDefaults: default values and helper functions forSearchBar.