Skip to content

Commit 9c842a2

Browse files
Material Design Teamymarian
Material Design Team
authored andcommitted
[BottomSheet] read the edgeToEdgeEnabled value earlier in the lifecycle
The DialogFragment will set the content view during the INITIALIZED state of the Lifecycle. This happens prior to onCreate and currently results in the edgeToEdgeEnabled value always being false at the time the OnApplyWindowInsertListener is conditionally set. PiperOrigin-RevId: 366294759 (cherry picked from commit 030e5bd)
1 parent a29c93a commit 9c842a2

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

+18-6
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,38 @@ public class BottomSheetDialog extends AppCompatDialog {
8383

8484
public BottomSheetDialog(@NonNull Context context) {
8585
this(context, 0);
86+
87+
edgeToEdgeEnabled =
88+
getContext()
89+
.getTheme()
90+
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
91+
.getBoolean(0, false);
8692
}
8793

8894
public BottomSheetDialog(@NonNull Context context, @StyleRes int theme) {
8995
super(context, getThemeResId(context, theme));
9096
// We hide the title bar for any style configuration. Otherwise, there will be a gap
9197
// above the bottom sheet when it is expanded.
9298
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
99+
100+
edgeToEdgeEnabled =
101+
getContext()
102+
.getTheme()
103+
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
104+
.getBoolean(0, false);
93105
}
94106

95107
protected BottomSheetDialog(
96108
@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
97109
super(context, cancelable, cancelListener);
98110
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
99111
this.cancelable = cancelable;
112+
113+
edgeToEdgeEnabled =
114+
getContext()
115+
.getTheme()
116+
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
117+
.getBoolean(0, false);
100118
}
101119

102120
@Override
@@ -123,12 +141,6 @@ protected void onCreate(Bundle savedInstanceState) {
123141
}
124142
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
125143
}
126-
127-
edgeToEdgeEnabled =
128-
getContext()
129-
.getTheme()
130-
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
131-
.getBoolean(0, false);
132144
}
133145

134146
@Override

0 commit comments

Comments
 (0)