Skip to content

Commit 90d6583

Browse files
committed
[Search] Update demos and doc to use AppBarLayout app:statusBarForeground in order to avoid overlap between SearchBar and status bar content
Resolves #3103 Resolves #3358 Resolves #3914 Resolves #3875 PiperOrigin-RevId: 590953070
1 parent ce386e4 commit 90d6583

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

catalog/java/io/material/catalog/search/res/layout/cat_search_fragment.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
android:id="@+id/nested_scroll_view"
2525
android:layout_width="match_parent"
2626
android:layout_height="match_parent"
27-
app:layout_behavior="@string/appbar_scrolling_view_behavior">
27+
app:layout_behavior="@string/searchbar_scrolling_view_behavior">
2828

2929
<TextView
3030
android:layout_width="match_parent"
3131
android:layout_height="wrap_content"
32-
android:paddingBottom="16dp"
33-
android:paddingLeft="16dp"
34-
android:paddingRight="16dp"
32+
android:layout_marginTop="88dp"
33+
android:layout_marginBottom="16dp"
34+
android:layout_marginLeft="16dp"
35+
android:layout_marginRight="16dp"
36+
android:fitsSystemWindows="true"
3537
android:lineSpacingMultiplier="1.2"
3638
android:text="@string/cat_searchbar_lorem_ipsum"/>
3739
</androidx.core.widget.NestedScrollView>
@@ -41,14 +43,13 @@
4143
android:layout_width="match_parent"
4244
android:layout_height="wrap_content"
4345
android:fitsSystemWindows="true"
44-
app:liftOnScroll="false">
46+
app:statusBarForeground="?attr/colorSurface">
4547

4648
<com.google.android.material.search.SearchBar
4749
android:id="@+id/cat_search_bar"
4850
android:layout_width="match_parent"
4951
android:layout_height="wrap_content"
50-
android:hint="@string/cat_searchbar_hint"
51-
app:layout_scrollEffect="compress">
52+
android:hint="@string/cat_searchbar_hint">
5253
</com.google.android.material.search.SearchBar>
5354
</com.google.android.material.appbar.AppBarLayout>
5455

catalog/java/io/material/catalog/search/res/layout/cat_search_recycler_fragment.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
android:layout_width="match_parent"
3939
android:layout_height="wrap_content"
4040
android:fitsSystemWindows="true"
41-
app:liftOnScroll="false">
41+
app:liftOnScroll="false"
42+
app:statusBarForeground="?attr/colorSurface">
4243

4344
<com.google.android.material.search.SearchBar
4445
android:id="@+id/open_search_bar"
4546
android:layout_width="match_parent"
4647
android:layout_height="wrap_content"
47-
android:hint="@string/cat_searchbar_hint"
48-
app:layout_scrollEffect="compress">
48+
android:hint="@string/cat_searchbar_hint">
4949
</com.google.android.material.search.SearchBar>
5050

5151
<com.google.android.material.tabs.TabLayout

docs/components/Search.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ The `SearchBar` can either be used as a fixed or scroll-away search field.
124124
#### Fixed Mode
125125

126126
To set up the fixed mode, simply position the `SearchBar` on top of the rest of
127-
your layout's contents and do not set up any scrolling behaviors. It will remain
128-
in place as the content is scrolled beneath it.
127+
your layout's contents and do not set up any scrolling behaviors or
128+
AppBarLayout. The `SearchBar` will remain fixed in place as the content is
129+
scrolled beneath it.
129130

130131
#### Scroll-away Mode
131132

@@ -140,6 +141,10 @@ child so that the `SearchBar` will overlap the rest of your content and appear
140141
to be floating above it. See the [XML usage](#usage) section below for an
141142
example of how to set up this behavior.
142143

144+
Additionally, if your app is going edge-to-edge, consider adding
145+
`app:statusBarForeground="?attr/colorSurface"` to your `AppBarLayout` in order
146+
to avoid overlap between the `SearchBar` and status bar content on scroll.
147+
143148
### Toolbar Transitions
144149

145150
The `SearchBar` component also provides transitions to and from a `Toolbar`,

0 commit comments

Comments
 (0)