material-components / material-components/material-components-android
[AppBarLayout] `fitsSystemWindows="true"` is ignored if wrapped inside `CoordinatorLayout` without `fitsSystemWindows`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:** With SDK 35 I had another look at edge-to-edge interactions. In my case I have a `androidx.coordinatorlayout.widget.CoordinatorLayout` as the root layout with a nested `com.google.android.material.appbar.AppBarLayout` that has `android:fitsSystemWindows="true"`. The activity sets `WindowCompat.setDecorFitsSystemWindows(getWindow(), false);` on creation. However, `android:fitsSystemWindows` doesn't seem to have any influence on the visuals, so any text from the toolbar (and potential menu controls) are behind transparent controls (if present).
As a workaround I wrote this snippet to apply the required padding manually:
```java
protected void addSystemPaddingToComponentNoBottom(View view) {
int originalLeftPadding = view.getPaddingLeft();
int originalTopPadding = view.getPaddingTop();
int originalRightPadding = view.getPaddingRight();
int originalBottomPadding = view.getPaddingBottom();
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
int leftPadding = originalLeftPadding + insets.left;
int topPadding = originalTopPadding + insets.top;
int rightPadding = originalRightPadding + insets.right;
view.setPadding(leftPadding, topPadding, rightPadding, originalBottomPadding);
return windowInsets;
});
}
```
If I apply this to all `com.google.android.material.appbar.AppBarLayout`s in my app, everything works as expected.
**Expected behavior:** I would `android:fitsSystemWindows="true"` to apply this inset by itself. it works without issues when using it on the root `CoordinatorLayout` (which I want to be visible behind the controls, so that's why this is not an option).
**Source code:**
```xml
```
Please not how `android:fitsSystemWindows="true"` works for the nested `CoordinatorLayout` without any issues.
**Android API version:** 35
**Material Library version:** 1.12.0
**Device:** Probably all of them, tested in Emulator with Pixel 4a API 31
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the SDK 35 configuration using the provided CoordinatorLayout, nested AppBarLayout, and WindowCompat.setDecorFitsSystemWindows setup. Start by tracing window-insets handling through AppBarLayout and CoordinatorLayout, comparing it with the nested CoordinatorLayout that works. Done means AppBarLayout applies the expected top and side system-bar insets without manual padding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100