androidx.compose.material3

SearchBarDefaultsExperimental

Object

No hand-written docs yet.

Defaults used in SearchBar and DockedSearchBar.

object SearchBarDefaults

Properties

TonalElevation

val TonalElevation: Dp

Default tonal elevation for a search bar.

ShadowElevation

val ShadowElevation: Dp

Default shadow elevation for a search bar.

InputFieldHeight

val InputFieldHeight: Dp

Default height for a search bar's input field, or a search bar in the unexpanded state.

inputFieldShape

@Composable val inputFieldShape: Shape

Default shape for a search bar's input field, or a search bar in the unexpanded state.

fullScreenShape

@Composable val fullScreenShape: Shape

Default shape for a SearchBar in the expanded state.

collapsedContainedSearchBarColorSince 1.11

@Composable val collapsedContainedSearchBarColor: Color

Default container color for an ExpandedFullScreenContainedSearchBar in the collapsed state.

fullScreenContainedSearchBarColorSince 1.11

@Composable val fullScreenContainedSearchBarColor: Color

Default container color for an ExpandedFullScreenContainedSearchBar in the expanded state.

dockedShape

@Composable val dockedShape: Shape

Default shape for a DockedSearchBar.

dockedDropdownShapeSince 1.11

val dockedDropdownShape: Shape

Default shape for a drop-down containing search results attached to a DockedSearchBar.

dockedDropdownGapSizeSince 1.11

val dockedDropdownGapSize: Dp

Default gap size for a drop-down attached to a DockedSearchBar.

dockedDropdownScrimColorSince 1.11

@Composable val dockedDropdownScrimColor: Color

Default scrim color for a drop-down attached to a DockedSearchBar.

AppBarContentPaddingSince 1.10

val AppBarContentPadding: PaddingValues

Default padding used for AppBarWithSearch content

windowInsets

@Composable val windowInsets: WindowInsets

Default window insets for an AppBarWithSearch.

fullScreenWindowInsetsSince 1.9

@Composable val fullScreenWindowInsets: WindowInsets

Default window insets used and consumed by ExpandedFullScreenSearchBar.

Functions

enterAlwaysSearchBarScrollBehaviorSince 1.9Experimental

@Composable
fun enterAlwaysSearchBarScrollBehavior(
    initialOffset: Float = 0f,
    initialOffsetLimit: Float = -Float.MAX_VALUE,
    initialContentOffset: Float = 0f,
    canScroll: () -> Boolean = { true },
    snapAnimationSpec: AnimationSpec<Float> = MotionSchemeKeyTokens.DefaultEffects.value(),
    flingAnimationSpec: DecayAnimationSpec<Float> = rememberSplineBasedDecay(),
    reverseLayout: Boolean = false,
): SearchBarScrollBehavior

Returns a SearchBarScrollBehavior. A search bar that is set up with this behavior will immediately scroll upward off-screen when the content is pulled up, and will immediately appear when the content is pulled down.

colors

@Composable
fun colors(
    containerColor: Color = SearchBarTokens.ContainerColor.value,
    dividerColor: Color = SearchViewTokens.DividerColor.value,
    inputFieldColors: TextFieldColors = inputFieldColors(),
): SearchBarColors

Creates a SearchBarColors that represents the different colors used in parts of the search bar.

containedColorsSince 1.11

@Composable
fun containedColors(state: SearchBarState): SearchBarColors

Creates a SearchBarColors that represents the different colors used in parts of the search bar based on SearchBarState.

appBarWithSearchColorsSince 1.10

@Composable
fun appBarWithSearchColors(
    searchBarColors: SearchBarColors = colors(),
    scrolledSearchBarContainerColor: Color = ColorSchemeKeyTokens.SurfaceContainerHighest.value,
    appBarContainerColor: Color = AppBarTokens.ContainerColor.value,
    scrolledAppBarContainerColor: Color = AppBarTokens.OnScrollContainerColor.value,
    appBarNavigationIconColor: Color = AppBarTokens.LeadingIconColor.value,
    appBarActionIconColor: Color = AppBarTokens.TrailingIconColor.value,
): AppBarWithSearchColors

Creates an AppBarWithSearchColors that represents the different colors used in parts of the AppBarWithSearch.

inputFieldColors

@Composable
fun inputFieldColors(
    focusedTextColor: Color = SearchBarTokens.InputTextColor.value,
    unfocusedTextColor: Color = SearchBarTokens.InputTextColor.value,
    disabledTextColor: Color = FilledTextFieldTokens.DisabledInputColor.value.copy(alpha = FilledTextFieldTokens.DisabledInputOpacity),
    cursorColor: Color = FilledTextFieldTokens.CaretColor.value,
    selectionColors: TextSelectionColors = LocalTextSelectionColors.current,
    focusedLeadingIconColor: Color = SearchBarTokens.LeadingIconColor.value,
    unfocusedLeadingIconColor: Color = SearchBarTokens.LeadingIconColor.value,
    disabledLeadingIconColor: Color = FilledTextFieldTokens.DisabledLeadingIconColor.value.copy(alpha = FilledTextFieldTokens.DisabledLeadingIconOpacity),
    focusedTrailingIconColor: Color = SearchBarTokens.TrailingIconColor.value,
    unfocusedTrailingIconColor: Color = SearchBarTokens.TrailingIconColor.value,
    disabledTrailingIconColor: Color = FilledTextFieldTokens.DisabledTrailingIconColor.value.copy(alpha = FilledTextFieldTokens.DisabledTrailingIconOpacity),
    focusedPlaceholderColor: Color = SearchBarTokens.SupportingTextColor.value,
    unfocusedPlaceholderColor: Color = SearchBarTokens.SupportingTextColor.value,
    disabledPlaceholderColor: Color = FilledTextFieldTokens.DisabledInputColor.value.copy(alpha = FilledTextFieldTokens.DisabledInputOpacity),
    focusedPrefixColor: Color = FilledTextFieldTokens.InputPrefixColor.value,
    unfocusedPrefixColor: Color = FilledTextFieldTokens.InputPrefixColor.value,
    disabledPrefixColor: Color = FilledTextFieldTokens.InputPrefixColor.value.copy(alpha = FilledTextFieldTokens.DisabledInputOpacity),
    focusedSuffixColor: Color = FilledTextFieldTokens.InputSuffixColor.value,
    unfocusedSuffixColor: Color = FilledTextFieldTokens.InputSuffixColor.value,
    disabledSuffixColor: Color = FilledTextFieldTokens.InputSuffixColor.value.copy(alpha = FilledTextFieldTokens.DisabledInputOpacity),
    focusedContainerColor: Color = Color.Transparent,
    unfocusedContainerColor: Color = Color.Transparent,
    disabledContainerColor: Color = Color.Transparent,
): TextFieldColors

Creates a TextFieldColors that represents the different colors used in the search bar input field in different states.

InputFieldExperimental

@Composable
fun InputField(
    textFieldState: TextFieldState,
    searchBarState: SearchBarState,
    onSearch: (String) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    readOnly: Boolean = false,
    textStyle: TextStyle = LocalTextStyle.current,
    placeholder: @Composable (() -> Unit)? = null,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    prefix: @Composable (() -> Unit)? = null,
    suffix: @Composable (() -> Unit)? = null,
    inputTransformation: InputTransformation? = null,
    outputTransformation: OutputTransformation? = null,
    scrollState: ScrollState = rememberScrollState(),
    shape: Shape = inputFieldShape,
    colors: TextFieldColors = inputFieldColors(),
    interactionSource: MutableInteractionSource? = null,
    keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
    lineLimits: TextFieldLineLimits = TextFieldLineLimits.SingleLine,
)

A text field to input a query in a search bar.

@Composable
fun InputField(
    state: TextFieldState,
    onSearch: (String) -> Unit,
    expanded: Boolean,
    onExpandedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    readOnly: Boolean = false,
    textStyle: TextStyle = LocalTextStyle.current,
    placeholder: @Composable (() -> Unit)? = null,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    prefix: @Composable (() -> Unit)? = null,
    suffix: @Composable (() -> Unit)? = null,
    inputTransformation: InputTransformation? = null,
    outputTransformation: OutputTransformation? = null,
    scrollState: ScrollState = rememberScrollState(),
    shape: Shape = inputFieldShape,
    colors: TextFieldColors = inputFieldColors(),
    interactionSource: MutableInteractionSource? = null,
)

A text field to input a query in a search bar.

@Composable
fun InputField(
    query: String,
    onQueryChange: (String) -> Unit,
    onSearch: (String) -> Unit,
    expanded: Boolean,
    onExpandedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    placeholder: @Composable (() -> Unit)? = null,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    colors: TextFieldColors = inputFieldColors(),
    interactionSource: MutableInteractionSource? = null,
)

A text field to input a query in a search bar.

Library docs

Defaults used in SearchBar and DockedSearchBar.