-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Inheriting StatusBar and NavigationBar background colors on modal pages #28568
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,13 +256,24 @@ public ModalFragment(IMauiContext mauiContext, Page modal) | |
|
|
||
| dialog.Window.SetBackgroundDrawable(TransparentColorDrawable); | ||
|
|
||
| var attributes = Context?.GetActivity()?.Window?.Attributes; | ||
| var mainActivityWindow = Context?.GetActivity()?.Window; | ||
| var attributes = mainActivityWindow?.Attributes; | ||
|
|
||
| if (attributes is not null) | ||
| { | ||
| dialog.Window.SetSoftInputMode(attributes.SoftInputMode); | ||
| } | ||
|
|
||
| if (mainActivityWindow is not null) | ||
| { | ||
| var navigationBarColor = mainActivityWindow.NavigationBarColor; | ||
| var statusBarColor = mainActivityWindow.StatusBarColor; | ||
| #pragma warning disable CA1422 | ||
| dialog.Window.SetNavigationBarColor(new AColor(navigationBarColor)); | ||
| dialog.Window.SetStatusBarColor(new AColor(statusBarColor)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking, should we maybe also take into account But there are also other options for light/dark icons on status and navigation bar, visibility options etc. Maybe that's why this issue was resolved the way it was using Community Toolkit? That would also explain why there is a way to create your own implementation of this workaround to copy all the values needed https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/platform-specific/dialogfragment-customization#create-you-own-service |
||
| #pragma warning restore CA1422 | ||
| } | ||
|
|
||
| return dialog; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 28552, "Changing StatusBar and NavigationBar background color doesn't work with Modal pages", PlatformAffected.Android)] | ||
| public class Issue28552 : ContentPage | ||
| { | ||
| public Issue28552() | ||
| { | ||
| Content = new Button() | ||
| { | ||
| Text = "Click to Open Modal", | ||
| AutomationId = "OpenModalButton", | ||
| Command = new Command(() => | ||
| { | ||
| #if ANDROID | ||
| Android.Views.Window window = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.Window; | ||
| #pragma warning disable CA1422 | ||
| window.SetNavigationBarColor(Android.Graphics.Color.Purple); | ||
| window.SetStatusBarColor(Android.Graphics.Color.Green); | ||
| #endif | ||
| Window!.Page!.Navigation.PushModalAsync(new ContentPage | ||
| { | ||
| Content = new Label | ||
| { | ||
| VerticalOptions = LayoutOptions.Center, | ||
| Text = "Hello from Maui!", | ||
| AutomationId = "LabelOnModalPage" | ||
| } | ||
| }, false); | ||
| }) | ||
| }; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #if ANDROID | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
| public class Issue28552 : _IssuesUITest | ||
| { | ||
| public Issue28552(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Changing StatusBar and NavigationBar background color doesn't work with Modal pages"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Navigation)] | ||
| public void StatusBarAndNavigationBarShouldInheritColor() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pending snapshot already available in the latest build. |
||
| { | ||
| App.WaitForElement("OpenModalButton"); | ||
| App.Click("OpenModalButton"); | ||
| App.WaitForElement("LabelOnModalPage"); | ||
| VerifyScreenshot(); | ||
| } | ||
| } | ||
| #endif | ||
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.
Could we detect API level and use
SetSystemBarsAppearancefor API 30+?