-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Apps compiled for 15.0 / 35 default displaying as Edge to Edge #24742
Comments
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:
|
Thanks for the quick solution. @Redth |
See #24742 for details. It seems to be a better compromise to disable this by default in MAUI apps. You can still opt out by including a similar style: ```xml <style name="DisableOptOutEdgeToEdgeEnforcement"> <item name="android:windowOptOutEdgeToEdgeEnforcement">false</item> </style> ``` And then applying it in a similar way, either by calling it before the `base.OnCreate(..)` in your activity subclass (in the OnCreate method override), or by registering for the ActivityOnCreate lifecycle callback. Eg: ```csharp protected override void OnCreate(Bundle? savedInstanceState) { // Disable Edge to Edge opt out by calling this before base.OnCreate() Theme?.ApplyStyle(Resource.Style.DisableOptOutEdgeToEdgeEnforcement, force: true); base.OnCreate(savedInstanceState); } ```
Hi @Redth, thanks for sharing this workaround. I'm on net8.0-android and I have the same issue. When trying to apply the workaround suggested above, the app won't compile with the following error message: 0>styles.xml(2): Error APT2260 : style attribute 'android:attr/windowOptOutEdgeToEdgeEnforcement' not found. Is the workaround net9.0-android only? Thanks |
It's Android API 35 only, which is technically only supported in .NET 9, however in .NET 8 you could technically still try to target API 35 by adding this to your AndroidManifest.xml file: <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="35" /> This goes inside the
|
Thank you! |
Android 35+ enforces apps extending "Edge to Edge" by default. See #24742 for details. For now, a better compromise is to disable this by default in MAUI apps, until we can provide better support for edge to edge within .NET MAUI itself as well as better safe area insets on Android. If you still want to manually make your app more compatible with edge to edge, you can disable this implicit opt out by overriding the default theme, changing the `maui_edgetoedge_optout` attribute to `false` and the theme yourself: ```xml <style name="MainThemeEdgeToEdge" parent="Maui.MainTheme.NoActionBar"> <item name="maui_edgetoedge_optout">false</item> </style> ``` And then applying the theme by calling it before the `base.OnCreate(..)` in your activity subclass (in the OnCreate method override): ```csharp protected override void OnCreate(Bundle? savedInstanceState) { SetTheme(Resource.Style.MainThemeEdgeToEdge); base.OnCreate(savedInstanceState); } ``` This also fixes a previous bug where we were always switching the theme based on the presence of the `maui_splash` attribute, not the actual value of the attribute. Finally, it moves more calls into native android and reduces the boundary crossing for this specific method. The new "Default" of opting out of the Edge to Edge enforcement on an Android 35+ device looks now like this: ![Screenshot_1729819287](https://github.com/user-attachments/assets/15ddc7fc-9334-4f92-82de-c0b7e19921db) If you revert to the old behaviour by disabling the opt out, it will look like this: ![Screenshot_1729819354](https://github.com/user-attachments/assets/1770259e-0a9e-49ea-860e-37e6131a09c4)
Thank you for the work-around @Redth. I've noticed the following error in my code for MainActivity however, the app still compiles, builds and runs in both debug and release. Not sure why this isn't found. I am on .NET9 so thought this would be supported. |
We can use #2342 to track improvements to Safe Area support in .NET MAUI. |
For someone looking to fix the same issue as me that doesnt have a values-v35 folder yet and no styles file in there. |
Hi @Redth I have tried to add android:targetSdkVersion="35". It, with .NET8, compiles and I can produce an APK. When I go to install and run it on a device < 35, the app crashes with a log similar to this: Going back to android:targetSdkVersion="34", the app does not crash. Is it absolutely necessary to switch to .NET9 to use android:targetSdkVersion="35"? |
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
andvalues/styles.xml
files:In the
values-v35/styles.xml
declare a style:You need to add a style with the same name in the
values/styles.xml
file (without the attribute):Now in your
MainActivity.cs
override theOnCreate(Bundle? savedInstanceState)
and apply the style you created: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
The text was updated successfully, but these errors were encountered: