Skip to content

Commit 81373b7

Browse files
Material Design Teamimhappi
authored andcommitted
[Search] Hide search view divider for M3E
This change hides the divider on search view between the toolbar and content. It prepares for the contained style in Material 3 Expressive. PiperOrigin-RevId: 859185807
1 parent 9b413fc commit 81373b7

5 files changed

Lines changed: 19 additions & 4 deletions

File tree

docs/components/Search.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ You can also set a centered style with:
8787

8888
The recommended way to display a `SearchBar` is now inside of an `AppBarLayout`.
8989
You can specify
90-
`android:theme="ThemeOverlay.Material3Expressive.AppBarWithSearch"`
91-
on your `AppBarLayout` to style your `AppBarLayout` and `SearchBar`
92-
automatically as an AppBar with Search.
90+
`android:theme="ThemeOverlay.Material3Expressive.AppBarWithSearch"` on your
91+
`AppBarLayout` to style your `AppBarLayout` and `SearchBar` automatically as an
92+
AppBar with Search.
9393

9494
The default `SearchBar` style for this theme overlay is the centered text
9595
configuration. If you would like to specify a start-aligned text `SearchBar`,
@@ -191,6 +191,7 @@ Element | Attribute | Related meth
191191
**Flag for navigation icon** | `app:hideNavigationIcon` | -- | `true`
192192
**Flag for `DrawerArrowDrawable`** | `app:useDrawerArrowDrawable` | -- | `false`
193193
**Flag for soft keyboard** | `app:autoShowKeyboard` | -- | `true`
194+
**Flag for divider** | `app:dividerVisible` | -- | `true`
194195

195196
#### Styles
196197

@@ -428,6 +429,7 @@ it such as:
428429

429430
</com.google.android.material.search.SearchView>
430431
```
432+
431433
### Scrolling behavior
432434

433435
The `SearchBar` can either be used as a fixed, scroll-away, or lift on scroll
@@ -557,6 +559,7 @@ Alternatively, an example of the lift on scroll mode is below:
557559
</com.google.android.material.search.SearchView>
558560
</androidx.coordinatorlayout.widget.CoordinatorLayout>
559561
```
562+
560563
### Toolbar transitions
561564

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

lib/java/com/google/android/material/search/SearchView.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public class SearchView extends FrameLayout
170170
@ColorInt private final int backgroundColor;
171171
private boolean useWindowInsetsController;
172172
private boolean statusBarSpacerEnabledOverride;
173+
private final boolean dividerVisible;
173174
@NonNull private TransitionState currentTransitionState = TransitionState.HIDDEN;
174175
private Map<View, Integer> childImportantForAccessibilityMap;
175176
private final OnTouchModeChangeListener touchModeChangeListener =
@@ -218,6 +219,7 @@ public SearchView(@NonNull Context context, @Nullable AttributeSet attrs, int de
218219
boolean hideNavigationIcon = a.getBoolean(R.styleable.SearchView_hideNavigationIcon, false);
219220
autoShowKeyboard = a.getBoolean(R.styleable.SearchView_autoShowKeyboard, true);
220221
backHandlingEnabled = a.getBoolean(R.styleable.SearchView_backHandlingEnabled, true);
222+
dividerVisible = a.getBoolean(R.styleable.SearchView_dividerVisible, true);
221223

222224
a.recycle();
223225

@@ -249,6 +251,7 @@ public SearchView(@NonNull Context context, @Nullable AttributeSet attrs, int de
249251
setUpEditText(textAppearanceResId, text, hint);
250252
setUpBackButton(useDrawerArrowDrawable, hideNavigationIcon);
251253
setUpClearButton();
254+
setUpDivider();
252255
setUpContentOnTouchListener();
253256
setUpInsetListeners();
254257

@@ -447,6 +450,10 @@ public void afterTextChanged(Editable s) {}
447450
});
448451
}
449452

453+
private void setUpDivider() {
454+
divider.setVisibility(dividerVisible ? VISIBLE : GONE);
455+
}
456+
450457
@SuppressLint("ClickableViewAccessibility") // Will be handled by accessibility delegate.
451458
private void setUpContentOnTouchListener() {
452459
contentContainer.setOnTouchListener(

lib/java/com/google/android/material/search/res-public/values/public.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<public name="forceDefaultNavigationOnClickListener" type="attr"/>
3030
<public name="tintNavigationIcon" type="attr"/>
3131
<public name="textCentered" type="attr"/>
32+
<public name="dividerVisible" type="attr"/>
3233
<public name="Widget.Material3.SearchBar" type="style"/>
3334
<public name="Widget.Material3.SearchBar.Outlined" type="style"/>
3435
<public name="Widget.Material3.SearchView" type="style"/>

lib/java/com/google/android/material/search/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
<!-- Whether the automatic back handling behavior should be enabled.
115115
Default is true. -->
116116
<attr name="backHandlingEnabled" format="boolean"/>
117+
<!-- Whether the divider between the toolbar and content is visible. Default is true. -->
118+
<attr name="dividerVisible" format="boolean"/>
117119
</declare-styleable>
118120

119121
</resources>

lib/java/com/google/android/material/search/res/values/styles.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
<item name="liftOnScroll">true</item>
4040
</style>
4141

42-
<style name="Widget.Material3Expressive.SearchView" parent="Widget.Material3.SearchView"/>
42+
<style name="Widget.Material3Expressive.SearchView" parent="Widget.Material3.SearchView">
43+
<item name="dividerVisible">false</item>
44+
</style>
4345

4446
<style name="Widget.Material3Expressive.SearchBar.CenteredText.AppBarWithSearch">
4547
<item name="defaultMarginsEnabled">false</item>

0 commit comments

Comments
 (0)