ActionBar Overlapping Activity Contents in Android 15
Problem Statement
When migrating apps to Android 15, developers encounter a visual regresssion where the ActionBar overlaps activity content at the top of the screen. This issue doesn't occur in Android 14 and earlier versions. The problem manifests when using the default ActionBar (without a custom Toolbar in XML) and appears as follows:
- Activity content renders behind the ActionBar
- UI elements are partially or fully obscured by the ActionBar
- Layout positioning differs unexpectedly from previous Android versions
Why This Happens
Android 15 (API 35) introduces stricter enforcement of edge-to-edge display requirements. The problematic behavior occurs due to:
<item name="android:windowContentOverlay">@null</item>
While this attribute worked in previous versions to prevent status bar shadows, in Android 15 it triggers the content overlap issue. The system now requires explicit configuration to position content correctly relative to system bars.
Recommended Solution
Add Theme Attribute (Best Approach)
Add this declaration to your themes.xml
file:
<style name="AppBaseTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Your existing attributes -->
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
<!-- Other theme items -->
</style>
Cross-version compatibility
Add this attribute to both themes.xml
and night/themes.xml
to ensure consistent behavior across day/night themes
Key Details
- Targets API 35+: The
tools:targetApi="35"
ensures compatibility with older Android versions - Opts out: Allows temporary exemption from new edge-to-edge restrictions
- Backward compatible: Doesn't affect behavior in Android 14 and below
Alternative Solutions
1. Use fitsSystemWindows Attribute
Add this to your root layout XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true"
...>
When to use this
This approach works well for simple layouts or when you need a quick solution without theme modifications
2. Combined Theme Attributes
Add all three attributes for comprehensive solution:
<style name="AppBaseTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
...
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
</style>
3. Programmatic Edge-to-Edge Handling
For full control over insets:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this); // 1. Enable edge-to-edge
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
ViewCompat.setOnApplyWindowInsetsListener(toolbar, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
params.topMargin = insets.top; // 2. Apply top inset
v.setLayoutParams(params);
return windowInsets;
});
}
Advanced Scenarios
Use this programmatic approach when:
- Implementing custom system bar behaviors
- Dynamically adjusting layout based on device configuration
- Creating immersive experiences
Conclusion
To resolve ActionBar overlap issues in Android 15:
- First try adding
android:windowOptOutEdgeToEdgeEnforcement
to your theme - For simpler layouts, try
android:fitsSystemWindows="true"
- Use programmatic solutions when custom handling is required
- Always test your solution on both new and old Android versions
These approaches maintain compatibility with older Android versions while ensuring proper layout behavior in Android 15, preventing content overlap under the ActionBar.