Search Bar
The SearchBar represents a floating search field with affordances for search and navigation.
Note: SearchBar does not support the setTitle and setSubtitle methods, or their corresponding xml attributes. Instead, use setHint or setText, or their corresponding xml attributes, to provide a text affordance for your .
The example below shows how to use the SearchBar and SearchView together:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- NestedScrollingChild goes here (NestedScrollView, RecyclerView, etc.). -->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/searchbar_scrolling_view_behavior">
<!-- Screen content goes here. -->
</androidx.core.widget.NestedScrollView>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.search.SearchBar
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/searchbar_hint" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.search.SearchView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/searchbar_hint"
app:layout_anchor="@id/search_bar">
<!-- Search suggestions/results go here (ScrollView, RecyclerView, etc.). -->
</com.google.android.material.search.SearchView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Content copied to clipboard
For more information, see the component developer guidance and design guidelines.
Constructors
Types
Link copied to clipboard
Callback for the animation started and stopped via startOnLoadAnimation and stopOnLoadAnimation.
Link copied to clipboard
Behavior that sets up the scroll-away mode for an SearchBar.
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun addOnLoadAnimationCallback(@NonNull onLoadAnimationCallback: SearchBar.OnLoadAnimationCallback)
Registers a callback for the On Load Animation, started and stopped via startOnLoadAnimation and stopOnLoadAnimation.
Link copied to clipboard
Link copied to clipboard
@CanIgnoreReturnValue
See collapse.
@CanIgnoreReturnValue
Starts a collapse animation, if it's not already started, which transitions from the
expandedView
, e.g.Link copied to clipboard
@CanIgnoreReturnValue
See expand.
@CanIgnoreReturnValue
Starts an expand animation, if it's not already started, which transitions from the to the
expandedView
, e.g.Link copied to clipboard
Returns the size in pixels of the SearchBar corners.
Link copied to clipboard
Returns the hint of main TextView.
Link copied to clipboard
Returns the color of the SearchBar outline stroke.
Link copied to clipboard
Returns the width in pixels of the SearchBar outline stroke.
Link copied to clipboard
Returns the text of main TextView, which usually represents the search text.
Link copied to clipboard
Link copied to clipboard
Returns whether the collapse animation is running.
Link copied to clipboard
Returns whether the default AppBarLayout scroll flags are enabled.
Link copied to clipboard
Returns whether the expand animation is running.
Link copied to clipboard
Returns whether the fade in part is enabled for the on load animation.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun removeOnLoadAnimationCallback(@NonNull onLoadAnimationCallback: SearchBar.OnLoadAnimationCallback): Boolean
Unregisters a callback for the On Load Animation, started and stopped via startOnLoadAnimation and stopOnLoadAnimation.
Link copied to clipboard
Sets whether the default AppBarLayout scroll flags are enabled.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Sets whether the fade in part is enabled for the on load animation.
Link copied to clipboard
Sets the color of the SearchBar outline stroke.
Link copied to clipboard
Sets the width in pixels of the SearchBar outline stroke.
Link copied to clipboard
SearchBar does not support the setSubtitle method, or its corresponding xml attribute.
Link copied to clipboard
SearchBar does not support the setTitle method, or its corresponding xml attribute.
Link copied to clipboard
Starts the on load animation which transitions from the center view to the hint .
Link copied to clipboard
Stops the on load animation which transitions from the center view to the hint .