Skip to content

[Android] Apps compiled for 15.0 / 35 default displaying as Edge to Edge #24742

@Redth

Description

@Redth

Description

Starting with Android 15.0 (API 35) apps are displayed 'Edge to Edge' by default. https://developer.android.com/about/versions/15/behavior-changes-15#window-insets

It seems that .NET MAUI still adds content insets when using Shell but when using normal pages it does not. The result is that page content extends underneath the system bars (status and navigation) where it previously did not on older android versions.

There is a way to opting out of the new behaviour:
https://medium.com/androiddevelopers/insets-handling-tips-for-android-15s-edge-to-edge-enforcement-872774e8839b

First, you need to add values-v35/styles.xml and values/styles.xml files:
android-35-edge-to-edge-opt-out-resources

In the values-v35/styles.xml declare a style:

<?xml version="1.0" encoding="utf-8" ?> 
<resources>
    <style name="OptOutEdgeToEdgeEnforcement">
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>

You need to add a style with the same name in the values/styles.xml file (without the attribute):

<?xml version="1.0" encoding="utf-8" ?> 
<resources>
    <style name="OptOutEdgeToEdgeEnforcement">
    </style>
</resources>

Now in your MainActivity.cs override the OnCreate(Bundle? savedInstanceState) and apply the style you created:

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle? savedInstanceState)
    {
        // Must apply the style before the DecorView setup
        Theme?.ApplyStyle(Resource.Style.OptOutEdgeToEdgeEnforcement, force: false);

        base.OnCreate(savedInstanceState);
    }
}

Version with bug

9.0.0-rc.1.24453.9

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Android 14.0 and older

Affected platforms

Android

Affected platform versions

Android 15.0 / API 35

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions