Search View
Layout that provides a full screen search view and can be used with SearchBar.
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.
Types
Link copied to clipboard
Behavior that sets up an SearchView with an SearchBar.
Link copied to clipboard
interface TransitionListener
Callback interface that provides important transition events for a SearchView.
Link copied to clipboard
enum TransitionState
Enum that defines the possible transition states of an SearchView.
Functions
Link copied to clipboard
Add a header view to this SearchView, which will be placed above the search text area.
Link copied to clipboard
Adds a listener to handle SearchView transitions such as showing and closing.
Link copied to clipboard
Link copied to clipboard
Call this method from onBackCancelled or handleOnBackCancelled so that the back handler can cancel the back animation.
Link copied to clipboard
Clears focus on the main EditText and hides the soft keyboard.
Link copied to clipboard
Link copied to clipboard
Returns the hint of main EditText.
Link copied to clipboard
Returns the search prefix text.
Link copied to clipboard
Returns the Toolbar used by the SearchView.
Link copied to clipboard
Call this method from onBackInvoked or handleOnBackPressed so that the back handler can complete the back animation, or handle back without progress in certain cases.
Link copied to clipboard
Hides the SearchView with an animation.
Link copied to clipboard
Inflate a menu to provide additional options.
Link copied to clipboard
Returns whether the navigation icon should be animated from the SearchBar to .
Link copied to clipboard
Returns whether the soft keyboard should be shown when the SearchView is shown.
Link copied to clipboard
Returns whether the menu items should be animated from the SearchBar to .
Link copied to clipboard
Returns whether or not this SearchView is set up with an SearchBar.
Link copied to clipboard
Returns whether the SearchView's main content view is shown or showing.
Link copied to clipboard
Returns whether the soft keyboard should be shown with
WindowInsetsController
.Link copied to clipboard
Remove all header views from the section above the search text area.
Link copied to clipboard
Remove a header view from the section above the search text area.
Link copied to clipboard
Removes a listener to handle SearchView transitions such as showing and closing.
Link copied to clipboard
Requests focus on the main EditText and shows the soft keyboard.
Link copied to clipboard
Sets whether the navigation icon should be animated from the SearchBar to .
Link copied to clipboard
Sets whether the soft keyboard should be shown when the SearchView is shown.
Link copied to clipboard
Link copied to clipboard
Sets whether the menu items should be animated from the SearchBar to .
Link copied to clipboard
Sets whether the SearchView is modal for accessibility, i.e.
Link copied to clipboard
open fun setOnMenuItemClickListener(@Nullable onMenuItemClickListener: Toolbar.OnMenuItemClickListener)
Set a listener to handle menu item clicks.
Link copied to clipboard
Sets the search prefix text.
Link copied to clipboard
Enables/disables the status bar spacer, which can be used in cases where the status bar is translucent and the SearchView should not overlap the status bar area.
Link copied to clipboard
Sets the 'touchscreenBlocksFocus' attribute of the nested toolbar.
Link copied to clipboard
Sets up this SearchView with an SearchBar, which will result in the being shown when the SearchBar is clicked.
Link copied to clipboard
Sets whether the soft keyboard should be shown with
WindowInsetsController
.Link copied to clipboard
Updates the visibility of the SearchView without an animation.
Link copied to clipboard
Shows the SearchView with an animation.
Link copied to clipboard
Call this method from onBackStarted or handleOnBackStarted so that the back handler can initialize and start animating.
Link copied to clipboard
Call this method from onBackProgressed or handleOnBackProgressed so that the back handler can continue animating with a new progress value.
Link copied to clipboard
Sets the soft input mode for this SearchView.