You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Net 9 Android - StatusBar Color overriden on modal pages #2370
In MAUI Android, when adding StatusBarBehavior to change the color, and then going to a modal page - the status bar color gets replaced with the colorPrimary color from colors.xml.
This only happens on NET 9. In NET 8 the status bar color remained the same as the previous page.
I think its because int NET 9 in the App.cs you have to create a new Window for the app shell, but is there a solution to the status bar changing?
protected override Window CreateWindow(IActivationState? activationState) { var window = new Window(new AppShell()); return window; }
Expected Behavior
In the modal page, the status bar color should be the same as the previous normal page. This was the behaviour in NET 8
Steps To Reproduce
Open repo
Run in NET 9 for Android and click on the button - see the status bar color change from orange to green/red.
Change to NET 8 - see the color stays orange throughout.
@brminnick Hi , you linked a generic pull request , are you saying that #2215 will fix the issue? do you have a nightly build release that we can test? thanks again for your free time you dedicate to this project
@gabsamples6 we aren't sure that will fix the this issue. But right now the MCT doesn't support .Net 9, it will when that PR gets merged, and if that doesn't fix this issue then we will investigate.
Probably the reason this is failing is because the change I made on how modal works in .Net Maiu, so we will need to update here, but any .net9 fix is blocked by the linked PR
@pictos thanks for your reply, loved your video on memory leaks! any idea when you will release .net 9 version as the .net maui team released the nuget SR2
@bijington Hi, I think the Maui team did a release yesterday but seems very minimal stuff , I guess what you are after is not included. What do you think?
@bijington actually they seem to have updated the release notes and there is way more stuff that original posted when they released the nuget. Does it have what you need to release the .net 9 version of the toolkit
@gabsamples6 they did another release (SR2.1) which does have the fix but it also has brought in another issue that we are now having to try and diagnose.
@brminnick @bijington@gabsamples6 I tested the linked repo using the latest package references and the issue still occurs. Should this actually be marked as completed?
This is something expected since .net maui changed the way how modal works, now it uses a DialogFragment, and it has it own Window, and that Window doesn't apply the same configuration as the Activity.Window. I'll need to think on how to re-design the code for StatusBar color, right now the work around should be this one
Details
#if ANDROIDusingAndroid.App;usingAndroidX.Activity;usingAndroidX.Fragment.App;usingFragmentManager=AndroidX.Fragment.App.FragmentManager;usingMicrosoft.Maui.Platform;usingAndroid.Views;usingAndroidX.Core.View;
#endif
usingCommunityToolkit.Maui;usingMicrosoft.Extensions.Logging;usingMicrosoft.Maui.LifecycleEvents;usingSystem.Diagnostics;namespaceTestStatusBar;publicstaticclassMauiProgram{publicstaticMauiAppCreateMauiApp(){varbuilder=MauiApp.CreateBuilder();builder.UseMauiApp<App>().UseMauiCommunityToolkit().ConfigureFonts(fonts =>{fonts.AddFont("OpenSans-Regular.ttf","OpenSansRegular");fonts.AddFont("OpenSans-Semibold.ttf","OpenSansSemibold");}).ConfigureLifecycleEvents(a =>{
#if ANDROIDa.AddAndroid(builder =>{builder.OnCreate((activity,bundle)=>{if(activityis not ComponentActivitycomponentActivity){return;}componentActivity.GetFragmentManager()?.RegisterFragmentLifecycleCallbacks(newMyFragmentLifecycleCallbacks((fm,f)=>{if(fisAndroidX.Fragment.App.DialogFragmentdialogFragment){varactivity=Platform.CurrentActivity;if(activityisnull)return;varstatusBarColor=activity.Window!.StatusBarColor;varplatformColor=newAndroid.Graphics.Color(statusBarColor);vardialog=dialogFragment.Dialog;Debug.Assert(dialogis not null);Debug.Assert(dialog.Windowis not null);varwindow=dialog.Window;dialog.Window.SetStatusBarColor(platformColor);boolisColorTransparent=platformColor==Android.Graphics.Color.Transparent;if(isColorTransparent){window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);window.SetFlags(WindowManagerFlags.LayoutNoLimits,WindowManagerFlags.LayoutNoLimits);}else{window.ClearFlags(WindowManagerFlags.LayoutNoLimits);window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds,WindowManagerFlags.DrawsSystemBarBackgrounds);}window.SetDecorFitsSystemWindows(!isColorTransparent);CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color.FromArgb("#FFA500"));}}),false);});});
#endif
});Routing.RegisterRoute("SecondPage",typeof(SecondPage));builder.Services.AddTransient<SecondPage>();
#if DEBUGbuilder.Logging.AddDebug();
#endif
returnbuilder.Build();}}
#if ANDROIDpublicclassMyFragmentLifecycleCallbacks(Action<AndroidX.Fragment.App.FragmentManager,AndroidX.Fragment.App.Fragment>onFragmentStarted):FragmentManager.FragmentLifecycleCallbacks{publicoverridevoidOnFragmentStarted(FragmentManagerfm,AndroidX.Fragment.App.Fragmentf){onFragmentStarted?.Invoke(fm,f);base.OnFragmentStarted(fm,f);}}
#
Reacted by Brandon Minnick, Skarzag, TheSundayDev, Yann Zahringer Ferrando and WMLPB
Thank you very much for your workaround and your fix. In my application this bug affects not only the StatusBar, but the NavigationBar as well. Have you fixed the NavigationBar, too?
@WMLPB didn't touch on navigationBar, if you can provide a small project that reproduces the issue I can take a look and do my best to include it on my current PR
I set the StatusBar colour and the NavigationBar colour in my styles.xml to a black background with white text. Additionally: I use the DevExpress CollectionView, and their ThemeManger interferes with the StatusBar and NavigationBar while the SplashScreen shows up. So, I set the ThemeManager to use a black background and white text in CreateMauiApp as well.
I don’t use the CommutityToolkit for this…
This worked fine in MAUI 7 and MAUI 8. But when I open a modal Page in MAUI 9, the colours get replaced with a light background and dark text.
Your workaround works fine for me. I reset the StatusBar colour and NavigationBar colour with it. Thank you very much for your workaround.
But, thinking about it… – isn’t this actually a bug in MAUI itself? Shouldn’t the DialogFragment use the same settings like the active Activity in the first place? Shouldn’t the MAUI team fix this?
But, thinking about it… – isn’t this actually a bug in MAUI itself? Shouldn’t the DialogFragment use the same settings like the active Activity in the first place? Shouldn’t the MAUI team fix this?
It's more an Android thing. On Maui we changed the modal navigation to use DialogFragment in order to make it more natural , but the DialogFragment has it own Window and that Window doesn't inherit the properties values and behavior of the MainActivity.Window (At least we didn't find a way to do it), so when a modal appears now this happens and would be our responsibility to make adjust that values. Probably my PR here will go to Maui, that way all 3rd vendors and devs will have a single place to configure and customize their modals
Activity
nixkuroi commentedon Dec 8, 2024
The Xaml override breaks the build as well. I had to comment out the following in MainPage.xaml for it to work.
<mct:StatusBarBehavior StatusBarColor="{Binding AppColor}"></mct:StatusBarBehavior>
gabsamples6 commentedon Dec 9, 2024
@brminnick Hi , you linked a generic pull request , are you saying that #2215 will fix the issue? do you have a nightly build release that we can test? thanks again for your free time you dedicate to this project
pictos commentedon Dec 9, 2024
@gabsamples6 we aren't sure that will fix the this issue. But right now the MCT doesn't support .Net 9, it will when that PR gets merged, and if that doesn't fix this issue then we will investigate.
Probably the reason this is failing is because the change I made on how modal works in .Net Maiu, so we will need to update here, but any .net9 fix is blocked by the linked PR
gabsamples6 commentedon Dec 9, 2024
@pictos thanks for your reply, loved your video on memory leaks! any idea when you will release .net 9 version as the .net maui team released the nuget SR2
bijington commentedon Dec 9, 2024
I don't think they have release SR2 yet. I think it's due out tomorrow. Once it is out I expect us to work hard to get it done quickly
gabsamples6 commentedon Dec 12, 2024
@bijington Hi, I think the Maui team did a release yesterday but seems very minimal stuff , I guess what you are after is not included. What do you think?
bijington commentedon Dec 12, 2024
Sadly you are correct. They released SR1.4 but we need SR2
gabsamples6 commentedon Dec 14, 2024
@bijington actually they seem to have updated the release notes and there is way more stuff that original posted when they released the nuget. Does it have what you need to release the .net 9 version of the toolkit
bijington commentedon Dec 14, 2024
@gabsamples6 they did another release (SR2.1) which does have the fix but it also has brought in another issue that we are now having to try and diagnose.
Zack-G-I-T commentedon Dec 18, 2024
@brminnick @bijington @gabsamples6 I tested the linked repo using the latest package references and the issue still occurs. Should this actually be marked as completed?
gabsamples6 commentedon Dec 18, 2024
Hi just to say that this is not fixed ticket should be re-opened
pictos commentedon Dec 19, 2024
This is something expected since .net maui changed the way how modal works, now it uses a DialogFragment, and it has it own Window, and that Window doesn't apply the same configuration as the Activity.Window. I'll need to think on how to re-design the code for StatusBar color, right now the work around should be this one
Details
WMLPB commentedon Jan 3, 2025
Hi Pictos,
Thank you very much for your workaround and your fix. In my application this bug affects not only the StatusBar, but the NavigationBar as well. Have you fixed the NavigationBar, too?
pictos commentedon Jan 3, 2025
@WMLPB didn't touch on navigationBar, if you can provide a small project that reproduces the issue I can take a look and do my best to include it on my current PR
WMLPB commentedon Jan 4, 2025
Hi Pictos,
Thank you very much for your kind reply.
I set the StatusBar colour and the NavigationBar colour in my styles.xml to a black background with white text. Additionally: I use the DevExpress CollectionView, and their ThemeManger interferes with the StatusBar and NavigationBar while the SplashScreen shows up. So, I set the ThemeManager to use a black background and white text in CreateMauiApp as well.
I don’t use the CommutityToolkit for this…
This worked fine in MAUI 7 and MAUI 8. But when I open a modal Page in MAUI 9, the colours get replaced with a light background and dark text.
Your workaround works fine for me. I reset the StatusBar colour and NavigationBar colour with it. Thank you very much for your workaround.
But, thinking about it… – isn’t this actually a bug in MAUI itself? Shouldn’t the DialogFragment use the same settings like the active Activity in the first place? Shouldn’t the MAUI team fix this?
pictos commentedon Jan 5, 2025
@WMLPB
It's more an Android thing. On Maui we changed the modal navigation to use DialogFragment in order to make it more natural , but the DialogFragment has it own Window and that Window doesn't inherit the properties values and behavior of the MainActivity.Window (At least we didn't find a way to do it), so when a modal appears now this happens and would be our responsibility to make adjust that values. Probably my PR here will go to Maui, that way all 3rd vendors and devs will have a single place to configure and customize their modals