SearchBarDefaults



Defaults used in SearchBar and DockedSearchBar.

Summary

Public functions

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

A text field to input a query in a search bar

android
SearchBarColors
@Composable
colors(containerColor: Color, dividerColor: Color)

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

android
SearchBarColors
@Composable
colors(
    containerColor: Color,
    dividerColor: Color,
    inputFieldColors: TextFieldColors
)

This function is deprecated. Search bars now take the input field as a parameter.

android
TextFieldColors
@Composable
inputFieldColors(
    focusedTextColor: Color,
    unfocusedTextColor: Color,
    disabledTextColor: Color,
    cursorColor: Color,
    selectionColors: TextSelectionColors,
    focusedLeadingIconColor: Color,
    unfocusedLeadingIconColor: Color,
    disabledLeadingIconColor: Color,
    focusedTrailingIconColor: Color,
    unfocusedTrailingIconColor: Color,
    disabledTrailingIconColor: Color,
    focusedPlaceholderColor: Color,
    unfocusedPlaceholderColor: Color,
    disabledPlaceholderColor: Color
)

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

android

Public properties

Dp

This property is deprecated. Renamed to TonalElevation.

android
Dp

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

android
Dp

Default shadow elevation for a search bar.

android
Dp

Default tonal elevation for a search bar.

android
Shape

Default shape for a DockedSearchBar.

android
Shape

Default shape for a SearchBar in the expanded state.

android
Shape

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

android
WindowInsets

Default window insets for a SearchBar.

android

Public functions

InputField

@ExperimentalMaterial3Api
@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
): Unit

A text field to input a query in a search bar

Parameters
query: String

the query text to be shown in the input field.

onQueryChange: (String) -> Unit

the callback to be invoked when the input service updates the query. An updated text comes as a parameter of the callback.

onSearch: (String) -> Unit

the callback to be invoked when the input service triggers the ImeAction.Search action. The current query comes as a parameter of the callback.

expanded: Boolean

whether the search bar is expanded and showing search results.

onExpandedChange: (Boolean) -> Unit

the callback to be invoked when the search bar's expanded state is changed.

modifier: Modifier = Modifier

the Modifier to be applied to this input field.

enabled: Boolean = true

the enabled state of this input field. When false, this component will not respond to user input, and it will appear visually disabled and disabled to accessibility services.

placeholder: (@Composable () -> Unit)? = null

the placeholder to be displayed when the query is empty.

leadingIcon: (@Composable () -> Unit)? = null

the leading icon to be displayed at the start of the input field.

trailingIcon: (@Composable () -> Unit)? = null

the trailing icon to be displayed at the end of the input field.

colors: TextFieldColors = inputFieldColors()

TextFieldColors that will be used to resolve the colors used for this input field in different states. See SearchBarDefaults.inputFieldColors.

interactionSource: MutableInteractionSource? = null

an optional hoisted MutableInteractionSource for observing and emitting Interactions for this input field. You can use this to change the search bar's appearance or preview the search bar in different states. Note that if null is provided, interactions will still happen internally.

colors

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

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

For colors used in the input field, see SearchBarDefaults.inputFieldColors.

Parameters
containerColor: Color = SearchBarTokens.ContainerColor.value

the container color of the search bar

dividerColor: Color = SearchViewTokens.DividerColor.value

the color of the divider between the input field and the search results

colors

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

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)
): TextFieldColors

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

Only a subset of the full list of TextFieldColors parameters are used in the input field. All other parameters have no effect.

Parameters
focusedTextColor: Color = SearchBarTokens.InputTextColor.value

the color used for the input text of this input field when focused

unfocusedTextColor: Color = SearchBarTokens.InputTextColor.value

the color used for the input text of this input field when not focused

disabledTextColor: Color = FilledTextFieldTokens.DisabledInputColor.value .copy(alpha = FilledTextFieldTokens.DisabledInputOpacity)

the color used for the input text of this input field when disabled

cursorColor: Color = FilledTextFieldTokens.CaretColor.value

the cursor color for this input field

selectionColors: TextSelectionColors = LocalTextSelectionColors.current

the colors used when the input text of this input field is selected

focusedLeadingIconColor: Color = SearchBarTokens.LeadingIconColor.value

the leading icon color for this input field when focused

unfocusedLeadingIconColor: Color = SearchBarTokens.LeadingIconColor.value

the leading icon color for this input field when not focused

disabledLeadingIconColor: Color = FilledTextFieldTokens.DisabledLeadingIconColor .value.copy(alpha = FilledTextFieldTokens.DisabledLeadingIconOpacity)

the leading icon color for this input field when disabled

focusedTrailingIconColor: Color = SearchBarTokens.TrailingIconColor.value

the trailing icon color for this input field when focused

unfocusedTrailingIconColor: Color = SearchBarTokens.TrailingIconColor.value

the trailing icon color for this input field when not focused

disabledTrailingIconColor: Color = FilledTextFieldTokens.DisabledTrailingIconColor .value.copy(alpha = FilledTextFieldTokens.DisabledTrailingIconOpacity)

the trailing icon color for this input field when disabled

focusedPlaceholderColor: Color = SearchBarTokens.SupportingTextColor.value

the placeholder color for this input field when focused

unfocusedPlaceholderColor: Color = SearchBarTokens.SupportingTextColor.value

the placeholder color for this input field when not focused

disabledPlaceholderColor: Color = FilledTextFieldTokens.DisabledInputColor.value .copy(alpha = FilledTextFieldTokens.DisabledInputOpacity)

the placeholder color for this input field when disabled

Public properties

Elevation

val ElevationDp

InputFieldHeight

val InputFieldHeightDp

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

ShadowElevation

val ShadowElevationDp

Default shadow elevation for a search bar.

TonalElevation

val TonalElevationDp

Default tonal elevation for a search bar.

dockedShape

val dockedShapeShape

Default shape for a DockedSearchBar.

fullScreenShape

val fullScreenShapeShape

Default shape for a SearchBar in the expanded state.

inputFieldShape

val inputFieldShapeShape

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

windowInsets

val windowInsetsWindowInsets

Default window insets for a SearchBar.