@@ -25,16 +25,6 @@ a search icon.
2525
2626** Note:** Images use various dynamic color schemes.
2727
28- Before you can use the Material Search components, you need to add a dependency
29- to the Material components for Android library. For more information, go to the
30- [ Getting started] ( https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md )
31- page.
32-
33- Note: Material Search was introduced in ` 1.8.0 ` . To use Material Search, make
34- sure you're depending on
35- [ library version ` 1.8.0 ` ] ( https://github.com/material-components/material-components-android/releases/tag/1.8.0 )
36- or later.
37-
3828## Design & API documentation
3929
4030* [ Material 3 (M3) spec] ( https://m3.material.io/components/search/overview )
@@ -91,17 +81,11 @@ Element | Attribute | Relat
9181
9282#### Styles
9383
94- Element | Style
95- ------------------------------ | -------------------------------------
96- ** Search Bar Default style** | ` Widget.Material3.SearchBar `
97- ** Search View Toolbar style** | ` Widget.Material3.SearchView.Toolbar `
98- ** Search View Toolbar height** | ` @dimen/m3_searchview_height `
99-
100- Default search bar style theme attribute: ` ?attr/materialSearchBarStyle ` .
101-
102- Search view toolbar theme attribute: ` ?attr/materialSearchViewToolbarStyle ` .
103- Search view toolbar height theme attribute:
104- ` ?attr/materialSearchViewToolbarHeight ` .
84+ Element | Style | Theme attribute
85+ ------------------------------ | ------------------------------------- | ---------------
86+ ** Search Bar Default style** | ` Widget.Material3.SearchBar ` | ` ?attr/materialSearchBarStyle `
87+ ** Search View Toolbar style** | ` Widget.Material3.SearchView.Toolbar ` | ` ?attr/materialSearchViewToolbarStyle `
88+ ** Search View Toolbar height** | ` @dimen/m3_searchview_height ` | ` ?attr/materialSearchViewToolbarHeight `
10589
10690### Search view
10791
@@ -121,21 +105,29 @@ Element | Attribute | Related meth
121105
122106#### Styles
123107
124- Element | Style
125- ----------------------------- | -----------------------------
126- ** Search View Default style** | ` Widget.Material3.SearchView `
127-
128- Default search view style theme attribute: ` ?attr/materialSearchViewStyle ` .
108+ | Element | Style | Theme attribute |
109+ | -------- | ----------------------------- | ------------------------------- |
110+ | ** Search View Default style** | ` Widget.Material3.SearchView ` | ` ?attr/materialSearchViewStyle ` |
129111
130112## Code implementation
131113
114+ Before you can use the Material Search components, you need to add a dependency
115+ to the Material components for Android library. For more information, go to the
116+ [ Getting started] ( https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md )
117+ page.
118+
119+ Note: Material Search was introduced in ` 1.8.0 ` . To use Material Search, make
120+ sure you're depending on
121+ [ library version ` 1.8.0 ` ] ( https://github.com/material-components/material-components-android/releases/tag/1.8.0 )
122+ or later.
123+
132124API and source code
133125
134126* [ Class definition] ( https://developer.android.com/reference/com/google/android/material/search/SearchView )
135127
136128* [ Class source] ( https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/search/SearchView.java )
137129
138- #### Search bar
130+ ### Adding Search bar
139131
140132The ` SearchBar ` component provides an implementation of the floating search
141133field. It extends ` Toolbar ` , so it supports a navigation icon, menu items, and
@@ -173,7 +165,7 @@ API and source code:
173165 * [ Class definition] ( https://developer.android.com/reference/com/google/android/material/search/SearchBar )
174166 * [ Class source] ( https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/search/SearchBar.java )
175167
176- #### Search view
168+ ### Adding Search view
177169
178170The ` SearchView ` component provides an implementation of a full-screen search
179171view which can be used to display back navigation, a search hint and text, menu
@@ -212,15 +204,15 @@ searchView
212204 });
213205```
214206
215- ## Making search components accessible
207+ ### Making search components accessible
216208
217209You should set a content description on a search bar and search view components
218210via the ` android:contentDescription ` attribute or ` setContentDescription ` method
219211so that screen readers such as TalkBack are able to announce their purpose or
220212action. Text rendered in these components are automatically provided to
221213accessibility services, so additional content labels are usually unnecessary.
222214
223- ## Transition listeners
215+ ### Transition listeners
224216
225217If you want to get callbacks for when the ` SearchView ` transitions between its
226218different animation states, you can add an ` SearchView.TransitionListener ` via
@@ -235,7 +227,7 @@ searchView.addTransitionListener(
235227 });
236228```
237229
238- ## Predictive back
230+ ### Predictive back
239231
240232The ` SearchView ` component automatically supports
241233[ predictive back] ( /third_party/java_src/android_libs/material_components/docs/foundations/PredictiveBack.md )
@@ -250,19 +242,15 @@ to see how the component behaves when a user swipes back.
250242
251243## Customizing search bar
252244
253- <details >
254- <summary ><h3 >Expand and collapse animations</h3 ></summary >
245+ ### Expand and collapse animations
255246
256247One of the biggest advantages of using the ` SearchView ` in conjunction with an
257248` SearchBar ` is that you will get the expand and collapse animations for free. If
258249you are just using a standalone ` SearchView ` without an ` SearchBar ` , then
259250showing or hiding the ` SearchView ` will result in slide up and slide down
260251transitions.
261252
262- </details >
263-
264- <details >
265- <summary ><h3 >Soft input modes</h3 ></summary >
253+ ### Soft input modes
266254
267255The recommended ` windowSoftInputMode ` when using an ` SearchBar ` and an
268256` SearchView ` is ` adjustNothing ` . There are a couple reasons for this:
@@ -287,10 +275,7 @@ Lastly, if you don't want the soft keyboard to show automatically when the
287275` SearchView ` is shown, you can set ` app:autoShowKeyboard="false" ` on your
288276` SearchView ` .
289277
290- </details >
291-
292- <details >
293- <summary ><h3 >Translucent status bar</h3 ></summary >
278+ ### Translucent status bar
294279
295280` SearchBar ` and ` SearchView ` come with support for a translucent status bar.
296281
@@ -304,20 +289,14 @@ the `SearchView`. If you are using either `FLAG_TRANSLUCENT_STATUS`
304289` SearchView ` will automatically add an extra spacer surface so that it fills the
305290space underneath the translucent status bar.
306291
307- </details >
308-
309- <details >
310- <summary ><h3 >Menu to back arrow animation</h3 ></summary >
292+ ### Menu to back arrow animation
311293
312294If you are using the ` SearchBar ` with a ` NavigationDrawer ` , you can set the
313295` app:useDrawerArrowDrawable ` attribute to ` true ` on your ` SearchView ` to enable
314296the "hamburger" menu to back arrow icon animation. This animation will happen
315297during the expand and collapse of the ` SearchView ` .
316298
317- </details >
318-
319- <details >
320- <summary ><h3 >Search prefix</h3 ></summary >
299+ ### Search prefix
321300
322301If you would like to show some prefix text before the main search ` EditText ` ,
323302you can make use of the ` app:searchPrefixText ` attribute. For example, setting
@@ -328,10 +307,7 @@ Additionally, with this pattern it is common to hide the back button to reduce
328307clutter, as navigation can be handled outside of the search view. This can be
329308accomplished by setting ` app:hideNavigationIcon="true" ` on your ` SearchView ` .
330309
331- </details >
332-
333- <details >
334- <summary ><h3 >Search history, suggestions, and results</h3 ></summary >
310+ ### Search history, suggestions, and results
335311
336312` SearchView ` is a view group component, meaning you can nest content inside of
337313it such as:
@@ -351,11 +327,7 @@ it such as:
351327
352328 </com .google.android.material.search.SearchView>
353329```
354-
355- </details >
356-
357- <details >
358- <summary ><h3 >Scrolling behavior</h3 ></summary >
330+ ### Scrolling behavior
359331
360332The ` SearchBar ` can either be used as a fixed, scroll-away, or lift on scroll
361333search field.
@@ -399,10 +371,7 @@ view. On the `SearchBar`, set `app:liftOnScroll=true` and set a
399371See the [ putting it all together] ( #putting-it-all-together ) section below for an
400372example of how to set up this behavior.
401373
402- </details >
403-
404- <details >
405- <summary ><h3 id =" putting-it-all-together " >Putting it all together</h3 ></summary >
374+ ### Putting it all together
406375
407376Putting it all together and using the scroll-away mode, the ` SearchBar ` and
408377` SearchView ` widgets can be used in your layout as such:
@@ -487,11 +456,7 @@ Alternatively, an example of the lift on scroll mode is below:
487456 </com .google.android.material.search.SearchView>
488457</androidx .coordinatorlayout.widget.CoordinatorLayout>
489458```
490-
491- </details >
492-
493- <details >
494- <summary ><h3 >Toolbar transitions</h3 ></summary >
459+ ### Toolbar transitions
495460
496461The ` SearchBar ` component also provides transitions to and from a ` Toolbar ` ,
497462e.g., for a contextual multi-select flow. These transitions are implemented as
@@ -511,5 +476,3 @@ if (searchBar.collapse(contextualToolbar, appBarLayout)) {
511476 return ;
512477}
513478```
514-
515- </details >
0 commit comments