Skip to content

Fix: [BUG] StatusBarBehavior is causing Android layouts to go behind status bar and navigation bar buttons on launch #2351#3189

Open
Pastajello wants to merge 27 commits intoCommunityToolkit:mainfrom
Pastajello:bugfix/2351-content-behind-statusbar
Open

Fix: [BUG] StatusBarBehavior is causing Android layouts to go behind status bar and navigation bar buttons on launch #2351#3189
Pastajello wants to merge 27 commits intoCommunityToolkit:mainfrom
Pastajello:bugfix/2351-content-behind-statusbar

Conversation

@Pastajello
Copy link
Copy Markdown
Contributor

@Pastajello Pastajello commented Apr 7, 2026

Description of Change

Hello!

In the course of investigating the issue I found that flag swapping that was done before is, apparently, no longer needed. Now, the changes are... quite small but impactful and I havent tested every scenario possible:

TitleViews on TitleViews off
Modal n/a ok
Shell ok ok
NavigationPage

so.... Its something to do still. When I have time I can go on and test.

API BEFORE AFTER Transparency
API29 29_before 29_after 29_after_transparent
35 35_before 35_after 35_after_transparent

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description) - I guess, but for now I added it as a separate project cause I cant figure out how to set up not working sample in current Sample project
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls - fixing a bug

Additional information

@Pastajello
Copy link
Copy Markdown
Contributor Author

@evgenyvalavin
Are you able to check the isssue with IOnGlobalLayoutListener on this PR? I've removed flag juggling it should help.

@Pastajello Pastajello marked this pull request as draft April 7, 2026 13:14
@TheCodeTraveler
Copy link
Copy Markdown
Collaborator

Thanks @Pastajello!

I'm sure you already know this (and it's probably why the PR is still in Draft), but I'll need you to remove MauiApp1 before we can merge this.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix an Android launch-time layout issue where applying StatusBarBehavior can cause content to render under the status bar / navigation bar, by adjusting how window flags and insets handling are applied on Android. It also adds a new MauiApp1 sample project intended to reproduce the issue and visually validate the fix, and wires that sample into the samples solution.

Changes:

  • Adjusts Android status bar window flag/insets behavior in StatusBar.android.cs.
  • Adds a new samples/MauiApp1 repro app (resources, platform stubs, pages) for validating the bug/fix.
  • Updates samples/CommunityToolkit.Maui.Sample.slnx to include the new sample project.

Reviewed changes

Copilot reviewed 34 out of 40 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs Updates Android window flag / insets handling for status bar behavior.
samples/MauiApp1/Resources/Styles/Styles.xaml Adds sample styling resources for the repro app.
samples/MauiApp1/Resources/Styles/Colors.xaml Adds sample color resources for the repro app.
samples/MauiApp1/Resources/Splash/splash.svg Adds splash asset for the repro app.
samples/MauiApp1/Resources/Raw/AboutAssets.txt Adds template raw asset for the repro app.
samples/MauiApp1/Resources/Images/dotnet_bot.png Adds an image asset used by the repro UI.
samples/MauiApp1/Resources/AppIcon/appiconfg.svg Adds app icon foreground asset for the repro app.
samples/MauiApp1/Resources/AppIcon/appicon.svg Adds app icon background asset for the repro app.
samples/MauiApp1/Properties/launchSettings.json Adds Windows launch settings for the repro app.
samples/MauiApp1/Platforms/Windows/Package.appxmanifest Adds Windows packaging manifest for the repro app.
samples/MauiApp1/Platforms/Windows/App.xaml.cs Adds WinUI app bootstrap for the repro app.
samples/MauiApp1/Platforms/Windows/App.xaml Adds WinUI app XAML entry for the repro app.
samples/MauiApp1/Platforms/Windows/app.manifest Adds Windows app manifest for the repro app.
samples/MauiApp1/Platforms/Tizen/tizen-manifest.xml Adds Tizen manifest stub for the repro app.
samples/MauiApp1/Platforms/Tizen/Main.cs Adds Tizen entry point stub for the repro app.
samples/MauiApp1/Platforms/MacCatalyst/Program.cs Adds MacCatalyst entry point stub for the repro app.
samples/MauiApp1/Platforms/MacCatalyst/Info.plist Adds MacCatalyst Info.plist for the repro app.
samples/MauiApp1/Platforms/MacCatalyst/Entitlements.plist Adds MacCatalyst entitlements for the repro app.
samples/MauiApp1/Platforms/MacCatalyst/AppDelegate.cs Adds MacCatalyst app delegate for the repro app.
samples/MauiApp1/Platforms/iOS/Resources/PrivacyInfo.xcprivacy Adds iOS privacy manifest for the repro app.
samples/MauiApp1/Platforms/iOS/Program.cs Adds iOS entry point for the repro app.
samples/MauiApp1/Platforms/iOS/Info.plist Adds iOS Info.plist for the repro app.
samples/MauiApp1/Platforms/iOS/AppDelegate.cs Adds iOS app delegate for the repro app.
samples/MauiApp1/Platforms/Android/Resources/values/colors.xml Adds Android color resources for the repro app.
samples/MauiApp1/Platforms/Android/MainApplication.cs Adds Android Application class for the repro app.
samples/MauiApp1/Platforms/Android/MainActivity.cs Adds Android MainActivity for the repro app.
samples/MauiApp1/Platforms/Android/AndroidManifest.xml Adds Android manifest for the repro app.
samples/MauiApp1/MauiProgram.cs Adds app builder initialization for the repro app.
samples/MauiApp1/MauiApp1.csproj Adds the repro project file and references.
samples/MauiApp1/MainPage.xaml.cs Adds sample main page code-behind for repro UI.
samples/MauiApp1/MainPage.xaml Adds sample main page UI to demonstrate insets/layout.
samples/MauiApp1/InitialPage.xaml.cs Adds initial page code-behind for repro navigation.
samples/MauiApp1/InitialPage.xaml Adds initial page UI for repro navigation.
samples/MauiApp1/AppShell.xaml.cs Adds Shell code-behind and initial navigation logic.
samples/MauiApp1/AppShell.xaml Adds Shell structure and attaches StatusBarBehavior for repro.
samples/MauiApp1/App.xaml.cs Adds Application bootstrap for the repro app.
samples/MauiApp1/App.xaml Adds Application resources for the repro app.
samples/CommunityToolkit.Maui.Sample.slnx Adds MauiApp1 to the samples solution.

Comment thread src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs Outdated
Comment thread samples/MauiApp1/AppShell.xaml.cs Outdated
Comment thread samples/MauiApp1/MauiApp1.csproj Outdated
Comment thread samples/MauiApp1/MauiApp1.csproj Outdated
Comment thread samples/MauiApp1/MauiProgram.cs Outdated
Comment thread samples/CommunityToolkit.Maui.Sample.slnx
@Pastajello
Copy link
Copy Markdown
Contributor Author

Pastajello commented Apr 9, 2026

I have removed the sample project, created a bit better sample butttt.... if we add this fix it breaks the BehaviorGalleryPage in the same way it is broken on API 35+ (or 31+, didnt check) as described here:

dotnet/maui#34886

Screenshot_1775745994

Yet... if we do this in BehaviorsGalleryPage ctor:
SafeAreaEdges = SafeAreaEdges.Default;

Which should be a default value for ContentPage it behaves correctly for all 29/35 (which I use for testing)

Should this be merged or wait for #34886 so it can be safely merged?

@Pastajello Pastajello marked this pull request as ready for review April 9, 2026 14:57
Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @Pastajello! I have some formatting / refactoring comments in the Sample to add to CoPilot's review of the code updates.

Comment thread samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj Outdated
Comment thread src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs Outdated
@TheCodeTraveler
Copy link
Copy Markdown
Collaborator

Thanks @Pastajello! I'm not too concerned about dotnet/maui#34886 as that is specific to .NET MAUI, not our toolkit.

I'm cool with adding SafeAreaEdges = SafeAreaEdges.Default;

Could you take a moment to respond to CoPilot's suggestions and either implement them if you deem it appropriate, or respond + resolve the comment if it's not.

I've also added some comments asking for formatting fixes.

Comment thread src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment on lines +134 to +138
static void ApplyWindowFlags(Window window)
{
bool isTransparent = platformColor == PlatformColor.Transparent;

if (isTransparent)
if (OperatingSystem.IsAndroidVersionAtLeast(30))
{
window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
ApplyAndroidApi30(window);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplyWindowFlags now always ends up calling SetDecorFitsSystemWindows(window, false) (via ApplyAndroidApi30/ApplyAndroidApiLessThan30). Previously opaque StatusBarColor values would set DecorFitsSystemWindows=true, and elsewhere in the repo dialogs still use a transparency check (e.g., DialogFragmentService.android.cs:140-145). This is a behavioral change for non-transparent colors and can make content lay out under system bars when it previously would not. Consider restoring a transparency-based decision for DecorFitsSystemWindows (or documenting an intentional breaking change).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on this comment from CoPilot, @Pastajello?

Copy link
Copy Markdown
Contributor Author

@Pastajello Pastajello Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. Yea so. DialogFragmentService.android.cs( and connected) from what I gather is an old(Net 9) fix for StatusBarBeahvior on ModalPages? Technically could be deprecated?

Recently #3123 was added and it re-introduced the fix for NET 10.

Removal of window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
is main fix in the PR basically - I've not seen an instance where it is needed - perhaps with all EdgeToEdge work in .NET 10.

Setting SetDecorFitsSystemWindows(window, !isTransparent) breaks transparency setting on normal/modal pages.

I've found that PR also partially fixes the #3009 if we remove broken line from Snackbar.android.cs : SetLayoutParametersForView
!TryGetPageActiveModalPage(out _) ||
which skips setting layout parameters for snack.

(and snacks on modal pages are generally broken..)

I'm starting to lose context with all the different paths I've changed and tested(and english is not my main language) so sorry for chaotic message.

Generally with .NET 10 beahvior of app changed heavily and I have no idea of inner MAUI working.

TheCodeTraveler and others added 7 commits April 15, 2026 10:40
…Behavior/OverflowingTitleViewPage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Behavior/BrokenTitleViewShell.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Behavior/BrokenTitleViewShell.xaml


ok

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] StatusBarBehavior is causing Android layouts to go behind status bar and navigation bar buttons on launch

5 participants