diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java
index 950b647152f..e77cb87ee3e 100644
--- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java
+++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java
@@ -32,6 +32,7 @@
import android.os.Build.VERSION_CODES;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.v4.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
@@ -231,6 +232,9 @@ public abstract static class BottomSheetCallback {
private boolean paddingLeftSystemWindowInsets;
private boolean paddingRightSystemWindowInsets;
private boolean paddingTopSystemWindowInsets;
+ private boolean marginLeftSystemWindowInsets;
+ private boolean marginRightSystemWindowInsets;
+ private boolean marginTopSystemWindowInsets;
private int insetBottom;
private int insetTop;
@@ -375,6 +379,12 @@ public BottomSheetBehavior(@NonNull Context context, @Nullable AttributeSet attr
// this is a breaking change from the old behavior the default is true.
paddingTopSystemWindowInsets =
a.getBoolean(R.styleable.BottomSheetBehavior_Layout_paddingTopSystemWindowInsets, true);
+ marginLeftSystemWindowInsets =
+ a.getBoolean(R.styleable.BottomSheetBehavior_Layout_marginLeftSystemWindowInsets, false);
+ marginRightSystemWindowInsets =
+ a.getBoolean(R.styleable.BottomSheetBehavior_Layout_marginRightSystemWindowInsets, false);
+ marginTopSystemWindowInsets =
+ a.getBoolean(R.styleable.BottomSheetBehavior_Layout_marginTopSystemWindowInsets, false);
a.recycle();
ViewConfiguration configuration = ViewConfiguration.get(context);
@@ -1462,6 +1472,10 @@ private void setWindowInsetsListener(@NonNull View child) {
if (!paddingBottomSystemWindowInsets
&& !paddingLeftSystemWindowInsets
&& !paddingRightSystemWindowInsets
+ && !paddingTopSystemWindowInsets
+ && !marginLeftSystemWindowInsets
+ && !marginRightSystemWindowInsets
+ && !marginTopSystemWindowInsets
&& !shouldHandleGestureInsets) {
return;
}
@@ -1471,7 +1485,11 @@ private void setWindowInsetsListener(@NonNull View child) {
@Override
public WindowInsetsCompat onApplyWindowInsets(
View view, WindowInsetsCompat insets, RelativePadding initialPadding) {
- insetTop = insets.getSystemWindowInsetTop();
+ Insets systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
+ Insets mandatoryGestureInsets =
+ insets.getInsets(WindowInsetsCompat.Type.mandatorySystemGestures());
+
+ insetTop = systemBarInsets.top;
boolean isRtl = ViewUtils.isLayoutRtl(view);
@@ -1480,13 +1498,13 @@ public WindowInsetsCompat onApplyWindowInsets(
int rightPadding = view.getPaddingRight();
if (paddingBottomSystemWindowInsets) {
- insetBottom = insets.getSystemWindowInsetBottom();
+ insetBottom = systemBarInsets.bottom;
bottomPadding = initialPadding.bottom + insetBottom;
}
if (paddingLeftSystemWindowInsets) {
leftPadding = isRtl ? initialPadding.end : initialPadding.start;
- leftPadding += insets.getSystemWindowInsetLeft();
+ leftPadding += systemBarInsets.left;
}
if (paddingRightSystemWindowInsets) {
@@ -1494,10 +1512,24 @@ public WindowInsetsCompat onApplyWindowInsets(
rightPadding += insets.getSystemWindowInsetRight();
}
+ MarginLayoutParams mlp = (MarginLayoutParams) view.getLayoutParams();
+ if (marginLeftSystemWindowInsets) {
+ mlp.leftMargin = systemBarInsets.left;
+ }
+
+ if (marginRightSystemWindowInsets) {
+ mlp.rightMargin = systemBarInsets.right;
+ }
+
+ if (marginTopSystemWindowInsets) {
+ mlp.topMargin = systemBarInsets.top;
+ }
+
+ view.setLayoutParams(mlp);
view.setPadding(leftPadding, view.getPaddingTop(), rightPadding, bottomPadding);
if (shouldHandleGestureInsets) {
- gestureInsetBottom = insets.getMandatorySystemGestureInsets().bottom;
+ gestureInsetBottom = mandatoryGestureInsets.bottom;
}
// Don't update the peek height to be above the navigation bar or gestures if these
diff --git a/lib/java/com/google/android/material/bottomsheet/res/values/attrs.xml b/lib/java/com/google/android/material/bottomsheet/res/values/attrs.xml
index 729f0e5ba9e..fc1ac051c64 100644
--- a/lib/java/com/google/android/material/bottomsheet/res/values/attrs.xml
+++ b/lib/java/com/google/android/material/bottomsheet/res/values/attrs.xml
@@ -81,6 +81,9 @@
+
+
+
diff --git a/lib/java/com/google/android/material/bottomsheet/res/values/styles.xml b/lib/java/com/google/android/material/bottomsheet/res/values/styles.xml
index 43ee4ad7152..7a4e5079e0e 100644
--- a/lib/java/com/google/android/material/bottomsheet/res/values/styles.xml
+++ b/lib/java/com/google/android/material/bottomsheet/res/values/styles.xml
@@ -67,6 +67,12 @@
diff --git a/lib/java/com/google/android/material/internal/res-public/values/public.xml b/lib/java/com/google/android/material/internal/res-public/values/public.xml
index 1e08997a89b..fd2901dd2eb 100644
--- a/lib/java/com/google/android/material/internal/res-public/values/public.xml
+++ b/lib/java/com/google/android/material/internal/res-public/values/public.xml
@@ -22,5 +22,8 @@
+
+
+
diff --git a/lib/java/com/google/android/material/internal/res/values/attrs.xml b/lib/java/com/google/android/material/internal/res/values/attrs.xml
index 0733f6dd9aa..7eb2eb4c6ba 100644
--- a/lib/java/com/google/android/material/internal/res/values/attrs.xml
+++ b/lib/java/com/google/android/material/internal/res/values/attrs.xml
@@ -59,6 +59,9 @@
+
+
+