From a5b47ed5f0bf3e4526c84c3c9a49410359d36842 Mon Sep 17 00:00:00 2001 From: redth Date: Thu, 24 Oct 2024 19:22:32 -0400 Subject: [PATCH 1/2] Android: Opt out of edge to edge enforcement on api 35+ See https://github.com/dotnet/maui/issues/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 ``` 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); } ``` --- src/Core/src/Platform/Android/MauiAppCompatActivity.cs | 7 +++++++ .../Platform/Android/Resources/values-v35/styles.xml | 10 ++++++++++ .../src/Platform/Android/Resources/values/styles.xml | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 src/Core/src/Platform/Android/Resources/values-v35/styles.xml diff --git a/src/Core/src/Platform/Android/MauiAppCompatActivity.cs b/src/Core/src/Platform/Android/MauiAppCompatActivity.cs index b35231c3e538..a4132f4a806c 100644 --- a/src/Core/src/Platform/Android/MauiAppCompatActivity.cs +++ b/src/Core/src/Platform/Android/MauiAppCompatActivity.cs @@ -13,6 +13,13 @@ public partial class MauiAppCompatActivity : AppCompatActivity protected override void OnCreate(Bundle? savedInstanceState) { + // https://github.com/dotnet/maui/issues/24742 + // By default we opt out of edge to edge enforcment on Android 35+ + // 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); + if (!AllowFragmentRestore) { // Remove the automatically persisted fragment structure; we don't need them diff --git a/src/Core/src/Platform/Android/Resources/values-v35/styles.xml b/src/Core/src/Platform/Android/Resources/values-v35/styles.xml new file mode 100644 index 000000000000..4d4ae5e1d23e --- /dev/null +++ b/src/Core/src/Platform/Android/Resources/values-v35/styles.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Core/src/Platform/Android/Resources/values/styles.xml b/src/Core/src/Platform/Android/Resources/values/styles.xml index 94d8753a00dd..dc13838b90c2 100644 --- a/src/Core/src/Platform/Android/Resources/values/styles.xml +++ b/src/Core/src/Platform/Android/Resources/values/styles.xml @@ -1,5 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/src/Core/src/Platform/Android/Resources/values/styles.xml b/src/Core/src/Platform/Android/Resources/values/styles.xml index dc13838b90c2..96ea5013d7c1 100644 --- a/src/Core/src/Platform/Android/Resources/values/styles.xml +++ b/src/Core/src/Platform/Android/Resources/values/styles.xml @@ -4,6 +4,8 @@ +