Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Core/src/Platform/Android/MauiAppCompatActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

@jonathanpeppers jonathanpeppers Oct 28, 2024

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.


if (!AllowFragmentRestore)
{
// Remove the automatically persisted fragment structure; we don't need them
Expand Down
14 changes: 14 additions & 0 deletions src/Core/src/Platform/Android/Resources/values-v35/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>

<!-- Opts out of edge to edge enforcement on API 35+ -->
<!-- https://github.com/dotnet/maui/issues/24742 -->
<style name="OptOutEdgeToEdgeEnforcement">
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
</style>

<style name="DisableOptOutEdgeToEdgeEnforcement">
<item name="android:windowOptOutEdgeToEdgeEnforcement">false</item>
</style>
Comment on lines +6 to +12
Copy link
Member

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.


</resources>
7 changes: 7 additions & 0 deletions src/Core/src/Platform/Android/Resources/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>

<!-- Empty Matching style for values-v35/styles.xml -->
<style name="OptOutEdgeToEdgeEnforcement">
</style>
<style name="DisableOptOutEdgeToEdgeEnforcement">
</style>

<!-- Base application theme. -->
<style name="Maui.MainTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/colorPrimary</item>
Expand Down
Loading