dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

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

Open Redth opened 1 week ago

Redth commented 1 week ago

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.MainTheme", 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

github-actions[bot] commented 1 week ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.