Skip to content

Commit 603f1ef

Browse files
hunterstichpekingme
authored andcommitted
[BottomSheet] Deprecated enableEdgeToEdge for bottom sheet dialogs on API 35+.
enableEdgeToEdge no longer takes effect on API 35 and above where edge-to-edge is now enforced. Use paddingLeft|Right|BottomSystemWindowInsets to automatically inset dialog content. Resolves #4749 Resolves #4732 Resolves #4367 PiperOrigin-RevId: 754982643
1 parent 7711191 commit 603f1ef

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

docs/components/BottomSheet.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -563,31 +563,26 @@ bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallback)
563563
<details>
564564
<summary><h3>Handling insets and fullscreen</h3></summary>
565565

566-
`BottomSheetBehavior` can automatically handle insets (such as for
567-
[edge to edge](https://developer.android.com/training/gestures/edge-to-edge)) by
568-
specifying any of these to true on the view:
566+
`BottomSheetBehavior` automatically handles window insets by applying padding to
567+
the top and bottom of the view and margins to the left and right. These
568+
paddings and margins can be customized by specifying any of the following
569+
attributes on the view:
569570

570571
* `app:paddingBottomSystemWindowInsets`
571572
* `app:paddingLeftSystemWindowInsets`
572573
* `app:paddingRightSystemWindowInsets`
573574
* `app:paddingTopSystemWindowInsets`
574575

575-
On API 21 and above the modal bottom sheet will be rendered fullscreen (edge to
576-
edge) if the navigation bar is transparent and `enableEdgeToEdge` is true.
577-
To enable edge-to-edge by default for modal bottom sheets, you can override
578-
`?attr/bottomSheetDialogTheme` like the below example (`enableEdgeToEdge` is
579-
already true in `ThemeOverlay.Material3.BottomSheetDialog`):
576+
* `app:marginLeftSystemWindowInsets`
577+
* `app:marginRightSystemWindowInsets`
578+
* `app:marginTopSystemWindowInsets`
580579

581-
```xml
582-
<style name="AppTheme" parent="Theme.Material3.*">
583-
...
584-
<item name="bottomSheetDialogTheme">@style/ThemeOverlay.App.BottomSheetDialog</item>
585-
</style>
580+
Modal bottom sheets are rendered fullscreen by default. On API 21-34, this can
581+
be overriden by setting `enableEdgeToEdge` to `false` in your
582+
`?attr/bottomSheetDialogTheme` ThemeOverlay. On API 35 and above,
583+
`enableEdgeToEdge` has been deprecated and will no longer take effect. To
584+
learn more, read about [edge-to-edge enforcement on Android 15](https://developer.android.com/about/versions/15/behavior-changes-15#edge-to-edge).
586585

587-
<style name="ThemeOverlay.App.BottomSheetDialog" parent="ThemeOverlay.Material3.BottomSheetDialog">
588-
<item name="android:navigationBarColor">@android:color/transparent<item>
589-
</style>
590-
```
591586
Insets can be added automatically if any of the padding attributes above are set
592587
to true in the style, either by updating the style passed to the constructor, or
593588
by updating the default style specified by the `?attr/bottomSheetDialogTheme`

lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@ protected BottomSheetDialog(
110110
}
111111

112112
private void initialize() {
113+
if (VERSION.SDK_INT >= VERSION_CODES.VANILLA_ICE_CREAM) {
114+
edgeToEdgeEnabled = true;
115+
return;
116+
}
117+
113118
final TypedArray a = getContext()
114119
.getTheme()
115120
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge});
116-
117121
edgeToEdgeEnabled = a.getBoolean(0, false);
118-
119122
a.recycle();
120123
}
121124

@@ -129,8 +132,10 @@ protected void onCreate(Bundle savedInstanceState) {
129132
super.onCreate(savedInstanceState);
130133
Window window = getWindow();
131134
if (window != null) {
132-
// The status bar should always be transparent because of the window animation.
133-
window.setStatusBarColor(0);
135+
if (VERSION.SDK_INT < VERSION_CODES.VANILLA_ICE_CREAM) {
136+
// The status bar should always be transparent because of the window animation.
137+
window.setStatusBarColor(0);
138+
}
134139

135140
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
136141
if (VERSION.SDK_INT < VERSION_CODES.M) {
@@ -180,9 +185,7 @@ public void onAttachedToWindow() {
180185
super.onAttachedToWindow();
181186
Window window = getWindow();
182187
if (window != null) {
183-
// If the navigation bar is transparent at all the BottomSheet should be edge to edge.
184-
boolean drawEdgeToEdge =
185-
edgeToEdgeEnabled && Color.alpha(window.getNavigationBarColor()) < 255;
188+
boolean drawEdgeToEdge = shouldDrawEdgeToEdge(window);
186189
if (container != null) {
187190
container.setFitsSystemWindows(!drawEdgeToEdge);
188191
}
@@ -199,6 +202,14 @@ public void onAttachedToWindow() {
199202
updateListeningForBackCallbacks();
200203
}
201204

205+
private boolean shouldDrawEdgeToEdge(Window window) {
206+
if (VERSION.SDK_INT >= VERSION_CODES.VANILLA_ICE_CREAM) {
207+
return true;
208+
}
209+
210+
return edgeToEdgeEnabled && Color.alpha(window.getNavigationBarColor()) < 255;
211+
}
212+
202213
@Override
203214
public void onDetachedFromWindow() {
204215
if (edgeToEdgeCallback != null) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<!-- Style to use for modal bottom sheets in this theme. -->
2222
<attr name="bottomSheetStyle" format="reference"/>
2323
<!-- Determines if the BottomSheetDialog should be shown in edge to edge mode. -->
24+
<!-- Deprecated. Edge to Edge is always enabled on API 35 and above. -->
2425
<attr name="enableEdgeToEdge" format="boolean" />
2526
<!-- Style of drag handle views when being used with bottom sheets. -->
2627
<attr name="bottomSheetDragHandleStyle" format="reference"/>

0 commit comments

Comments
 (0)