Skip to content

Commit cb5dc7f

Browse files
committed
[Docs][Search] Update doc with more info on SearchView EditText and nested content
Resolves #4189 PiperOrigin-RevId: 636998698
1 parent 2bc1a2f commit cb5dc7f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/components/Search.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ searchView.setOnMenuItemClickListener(
186186
});
187187
```
188188

189-
Additionally, here is an example of how you can carry over the search text to
189+
Additionally, `SearchView` exposes its main `EditText` via a `getEditText()`
190+
method, so you can use any of the traditional
191+
[EditText APIs](https://developer.android.com/reference/android/widget/EditText)
192+
to configure the search field (`setText()`, `addTextChangedListener()`, etc.).
193+
194+
Here is an example of how you can carry over the search text to
190195
the `SearchBar`, as well as hide the `SearchView` when the user finishes typing
191196
and presses enter:
192197

@@ -317,6 +322,27 @@ Additionally, with this pattern it is common to hide the back button to reduce
317322
clutter, as navigation can be handled outside of the search view. This can be
318323
accomplished by setting `app:hideNavigationIcon="true"` on your `SearchView`.
319324

325+
## Search History, Suggestions, and Results
326+
327+
`SearchView` is a view group component, meaning you can nest content inside of
328+
it such as:
329+
330+
- Search history when the `SearchView` is first expanded
331+
- Search suggestions when the user is typing
332+
- Search results once the user submits the search
333+
334+
```xml
335+
<com.google.android.material.search.SearchView
336+
android:layout_width="match_parent"
337+
android:layout_height="match_parent"
338+
android:hint="@string/searchbar_hint"
339+
app:layout_anchor="@id/search_bar">
340+
341+
<!-- Search suggestions/results go here (ScrollView, RecyclerView, etc.). -->
342+
343+
</com.google.android.material.search.SearchView>
344+
```
345+
320346
## Putting it all together
321347

322348
Putting it all together and using the scroll-away mode, the `SearchBar` and
@@ -350,7 +376,9 @@ Putting it all together and using the scroll-away mode, the `SearchBar` and
350376
android:layout_height="match_parent"
351377
android:hint="@string/searchbar_hint"
352378
app:layout_anchor="@id/search_bar">
379+
353380
<!-- Search suggestions/results go here (ScrollView, RecyclerView, etc.). -->
381+
354382
</com.google.android.material.search.SearchView>
355383
</androidx.coordinatorlayout.widget.CoordinatorLayout>
356384
```

0 commit comments

Comments
 (0)