Skip to content

Commit

Permalink
[Search] Update demos and doc to use AppBarLayout app:statusBarForegr…
Browse files Browse the repository at this point in the history
…ound in order to avoid overlap between SearchBar and status bar content

Resolves #3103
Resolves #3358
Resolves #3914
Resolves #3875

PiperOrigin-RevId: 590953070
  • Loading branch information
dsn5ft committed Dec 14, 2023
1 parent ce386e4 commit 90d6583
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
app:layout_behavior="@string/searchbar_scrolling_view_behavior">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginTop="88dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:fitsSystemWindows="true"
android:lineSpacingMultiplier="1.2"
android:text="@string/cat_searchbar_lorem_ipsum"/>
</androidx.core.widget.NestedScrollView>
Expand All @@ -41,14 +43,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="false">
app:statusBarForeground="?attr/colorSurface">

<com.google.android.material.search.SearchBar
android:id="@+id/cat_search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_searchbar_hint"
app:layout_scrollEffect="compress">
android:hint="@string/cat_searchbar_hint">
</com.google.android.material.search.SearchBar>
</com.google.android.material.appbar.AppBarLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="false">
app:liftOnScroll="false"
app:statusBarForeground="?attr/colorSurface">

<com.google.android.material.search.SearchBar
android:id="@+id/open_search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_searchbar_hint"
app:layout_scrollEffect="compress">
android:hint="@string/cat_searchbar_hint">
</com.google.android.material.search.SearchBar>

<com.google.android.material.tabs.TabLayout
Expand Down
9 changes: 7 additions & 2 deletions docs/components/Search.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ The `SearchBar` can either be used as a fixed or scroll-away search field.
#### Fixed Mode

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

#### Scroll-away Mode

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

Additionally, if your app is going edge-to-edge, consider adding
`app:statusBarForeground="?attr/colorSurface"` to your `AppBarLayout` in order
to avoid overlap between the `SearchBar` and status bar content on scroll.

### Toolbar Transitions

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

0 comments on commit 90d6583

Please sign in to comment.