-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: Opt out of edge to edge enforcement on api 35+ #25517
base: main
Are you sure you want to change the base?
Conversation
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); } ```
This will make it easier for devs to intentionally revert the implied opt-out of android 35 edge to edge enforcement behaviour that this PR also adds to MAUI. Now all that's needed is to apply the disable style like this: ```csharp protected override void OnCreate(Bundle? savedInstanceState) { Theme?.ApplyStyle(Microsoft.Maui.Resource.Style.DisableOptOutEdgeToEdgeEnforcement, force: true); base.OnCreate(savedInstanceState); } ```
// Must be applied before the DecorView is setup | ||
// We set force to false in case the style has already been explicitly | ||
// applied to disable opting out of edge to edge enforcement | ||
Theme?.ApplyStyle(Resource.Style.OptOutEdgeToEdgeEnforcement, force: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work to set this in Maui.MainTheme
:
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
And just set it no matter what, probably doesn't do anything on API < 35?
This would avoid a C# -> Java call on startup.
<style name="OptOutEdgeToEdgeEnforcement"> | ||
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item> | ||
</style> | ||
|
||
<style name="DisableOptOutEdgeToEdgeEnforcement"> | ||
<item name="android:windowOptOutEdgeToEdgeEnforcement">false</item> | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you wouldn't even really need these styles.
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 including a similar (inverse) style:
And then applying it in the same way by calling it before the
base.OnCreate(..)
in your activity subclass (in the OnCreate method override):The new "Default" of opting out of the Edge to Edge enforcement on an Android 35+ device looks now like this:
If you revert to the old behaviour by disabling the opt out, it will look like this: