Skip to content

Add Support for StatusBarBehavior in Android Modal Page#3123

Merged
TheCodeTraveler merged 17 commits intomainfrom
Add-Support-For-Android-StatusBarBehavior-in-Modal-Page
Mar 23, 2026
Merged

Add Support for StatusBarBehavior in Android Modal Page#3123
TheCodeTraveler merged 17 commits intomainfrom
Add-Support-For-Android-StatusBarBehavior-in-Modal-Page

Conversation

@TheCodeTraveler
Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler commented Feb 27, 2026

Description of Change

This PR updates StatusBar.android.cs to get the current window, checking to see if a Modal Page is being displayed.

Because MAUI uses a Dialog with its own Window, not the Activity's Window for modal pages, Platform.CurrentActivity?.Window gives the wrong window when a modal is displayed. This PR updates the extension method GetCurrentWindow() to check for a DialogFragment (aka a .NET MAUI Modal Page on Android) and returns the DialogFragment's Window.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

Additional information

This PR also removes duplicate methods from PropertyChangedEventArgsExtensions and updates the Sample App UI for StatusBarPage and NavigationBarPage

ScreenFlow

Copilot AI review requested due to automatic review settings February 27, 2026 20:28
Copy link
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 make StatusBarBehavior work correctly on Android modal pages by resolving and targeting the active modal Window (DialogFragment window) instead of always using the hosting Activity’s window. It also simplifies a shared property-changed helper and refreshes the sample UI layout for StatusBar/NavigationBar pages.

Changes:

  • Update Android StatusBar implementation to resolve the “current window” (including modal DialogFragment windows) before applying color/style.
  • Replace multiple IsOneOf overloads with a single variadic helper in PropertyChangedEventArgsExtensions.
  • Update sample view model defaults and tweak sample XAML layout for StatusBar/NavigationBar selection UI.

Reviewed changes

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

Show a summary per file
File Description
src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs Consolidates property-name helper methods into a single IsOneOf API.
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs Applies status bar changes to the appropriate Android Window, including modals.
samples/.../StatusBarBehaviorViewModel.cs Adjusts sample defaults for initial UI state.
samples/.../NavigationBarPage.xaml Refactors sample layout for NavigationBar style selection.
samples/.../StatusBarBehaviorPage.xaml Refactors sample layout/formatting for style selection and modal button.

…droid.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 27, 2026 20:34
Copy link
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 5 out of 5 changed files in this pull request and generated 4 comments.

Copilot AI review requested due to automatic review settings February 27, 2026 20:44
Copy link
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 5 out of 5 changed files in this pull request and generated 3 comments.

Copy link
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 6 out of 6 changed files in this pull request and generated 5 comments.

…roid.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 27, 2026 21:03
Copy link
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 6 out of 6 changed files in this pull request and generated 1 comment.

window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds);
}

WindowCompat.SetDecorFitsSystemWindows(window, !isColorTransparent);
Copy link
Member

Choose a reason for hiding this comment

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

This method is deprecated on Android API 36. It is highly recommended that we add a check and only use it on an OS using a lower API.

bool isColorTransparent = platformColor == PlatformColor.Transparent;
if (isColorTransparent)
{
window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
Copy link
Member

Choose a reason for hiding this comment

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

I don't know any other way to deal with issue of status bar transparency but settings and clearing flags can and will interfere with developers attempts to set or use full screen and in a test app I had to remove all the settings and clearing of flags to have my app do what I wanted. I removed it throughout the toolkit where I found it in statusbar.

I am not sure what we should do here. This is more a comment about the current state of the behavior of hiding/showing status bar is a complicated mess atm and depending on API level settings these options will have completely different behavior on each API.

I do not advocate ripping out the flags I am simply stating all of my use cases do require it. It would have significant impact on all API below 36 so I am not suggesting we do that. Just maybe add checks and block the changes for android 36?

Choose a reason for hiding this comment

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

It might be a good idea to add full-screen mode to CommunityToolkit.Maui so it doesn't interfere with the color change. We could also use an IsVisible boolean on the status bar and navigation bar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@IgrisModz sure! What specifically do we need to add?

Do you have any links to documentation you could share?

Copy link
Member

@ne0rrmatrix ne0rrmatrix left a comment

Choose a reason for hiding this comment

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

The issue I was having was unrelated to flags and I am happy to now approve this pr. I found out the issue was with my app and has nothing to do with @TheCodeTraveler code. It was all me. Anyways these changes do fix the issues they raised and I will be very happy to see the fixes live.

@TheCodeTraveler TheCodeTraveler merged commit eee32e1 into main Mar 23, 2026
10 checks passed
@TheCodeTraveler TheCodeTraveler deleted the Add-Support-For-Android-StatusBarBehavior-in-Modal-Page branch March 23, 2026 15:04
@AlleSchonWeg
Copy link

Hi @TheCodeTraveler ,
google have deprecated the Statusbar and Navigationbar coloring, because we have to use EdeToEdge with correct insets. Adding an overlay view looks like a hack. 🤣

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] StatusBar.SetColor Transparent Misbehaves in Edge-to-Edge [BUG] StatusBarBehaviour doesn't work for modal pages in .net MAUI 10

5 participants