material-components/material-components-android · error · IllegalStateException
Sheet view has been laid out; sheet edge cannot be changed o
Error message
Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid out.
What it means
SheetDialog.setSheetEdge() throws IllegalStateException when the sheet view has already been laid out. Runtime edge changes are unsupported: the sheet's behavior, delegate, and animations are bound to the initial edge, so once View.isLaidOut() is true the API refuses the change to avoid inconsistent state.
Source
Thrown at lib/java/com/google/android/material/sidesheet/SheetDialog.java:347
return container;
}
/**
* Set the edge which the sheet should originate from.
*
* <p>Note: This method should be called when the sheet is initialized, before it is shown.
* Runtime sheet edge changes are not supported.
*
* @throws IllegalStateException if the sheet is null or has already been laid out
* @param gravity the edge from which the sheet and its animations should originate.
*/
public void setSheetEdge(@GravityInt int gravity) {
if (sheet == null) {
throw new IllegalStateException(
"Sheet view reference is null; sheet edge cannot be changed if the sheet view is null.");
}
if (sheet.isLaidOut()) {
throw new IllegalStateException(
"Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid"
+ " out.");
}
ViewGroup.LayoutParams layoutParams = sheet.getLayoutParams();
if (layoutParams instanceof CoordinatorLayout.LayoutParams) {
((CoordinatorLayout.LayoutParams) layoutParams).gravity = gravity;
maybeUpdateWindowAnimationsBasedOnLayoutDirection();
}
}
private void maybeUpdateWindowAnimationsBasedOnLayoutDirection() {
Window window = getWindow();
if (window != null
&& sheet != null
&& sheet.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {
CoordinatorLayout.LayoutParams layoutParams =
(CoordinatorLayout.LayoutParams) sheet.getLayoutParams();
int absoluteGravity =View on GitHub (pinned to ac7e18efee)
Solutions
- Dismiss and recreate the SheetDialog when the edge must change, calling setSheetEdge(gravity) before show() (right after construction the sheet is null — set it in onCreate after setContentView, or right after show() before layout).
- Apply the edge preference at dialog construction time each session instead of mutating a live dialog.
- If mid-session switching is required, drive it through SideSheetBehavior on a fresh sheet instance rather than the dialog API.
Example fix
// before sideSheetDialog.setSheetEdge(Gravity.LEFT); // throws: sheet already laid out / shown // after sideSheetDialog.dismiss(); sideSheetDialog = SideSheetDialog(context); sideSheetDialog.show(); sideSheetDialog.setSheetEdge(Gravity.LEFT); // fresh sheet, not yet laid out
Defensive patterns
Strategy: validation
Validate before calling
if (!sheetView.isLaidOut()) {
dialog.setSheetEdge(gravity);
} else {
recreateDialogWithEdge(gravity);
} Prevention
- Recreate SheetDialog instances instead of reconfiguring live ones.
- Read the Javadoc contract: edge changes are init-time only, never runtime.
When it happens
Trigger: Calling setSheetEdge(...) on a sheet dialog that is currently shown or has been shown once (the sheet passed a layout pass); e.g. toggling the edge from a menu action while the sheet is open.
Common situations: Persisted 'side sheet on left/right' user preference applied after the first show; reusing a dialog instance and calling setSheetEdge on subsequent shows; edge-switch UI inside the sheet itself.
Related errors
- Sheet view reference is null; sheet edge cannot be changed i
- The view is not associated with SideSheetBehavior
- dateSelector should not be null. Use MaterialTextInputPicker
- Invalid sheet edge position value: %d. Must be %d or %d.
- Unexpected value: %s
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/60854a37131b43e1.
Report an issue: GitHub.