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
I want the modern android app look where the content background ist the same as the status bar background and it adapts depending on dark and light mode. To achieve this I tried using the CommunityToolkit StatusbarBehaviour from C# code to dynamically adjust but at the moment it works for a brief moment at the start of the app and then it switches to the primary color of the colors.xaml.
Does anyone know a reliable solution to implement this basic feature in a .NET MAUI app?
Here is my workaround I tried to use in AppShell.xaml.cs:
#if ANDROIDprivateStatusBarBehavior_androidStatusBarBehavior=null!;
#endif
publicAppShell(){InitializeComponent();
#if ANDROIDSetupAndroidStatusBar();
#endif
}
#if ANDROIDprivatevoidSetupAndroidStatusBar(){_androidStatusBarBehavior=newStatusBarBehavior{ApplyOn=StatusBarApplyOn.OnBehaviorAttachedTo};Behaviors.Add(_androidStatusBarBehavior);// initial configApplyThemeToSystemBars();if(Application.Current!=null){// subscribe to event for theme changes to update the behaviorApplication.Current.RequestedThemeChanged+=(s,e)=>ApplyThemeToSystemBars();}}privatevoidApplyThemeToSystemBars(){varisDark=Application.Current?.RequestedTheme==AppTheme.Dark;varwindow=Platform.CurrentActivity?.Window;if(window==null)return;varcontroller=newWindowInsetsControllerCompat(window,window.DecorView);if(isDark){_androidStatusBarBehavior.StatusBarStyle=StatusBarStyle.LightContent;controller.AppearanceLightNavigationBars=false;if(Application.Current?.Resources.TryGetValue("DarkBackground",outvarvalue)??false){vardarkColor=(Color)value;_androidStatusBarBehavior.StatusBarColor=darkColor;
#pragma warning disable CA1422window.SetNavigationBarColor(darkColor.ToPlatform());
#pragma warning restore CA1422}}else{_androidStatusBarBehavior.StatusBarStyle=StatusBarStyle.DarkContent;controller.AppearanceLightNavigationBars=true;if(Application.Current?.Resources.TryGetValue("LightBackground",outvarvalue)??false){varlightColor=(Color)value;_androidStatusBarBehavior.StatusBarColor=lightColor;
#pragma warning disable CA1422window.SetNavigationBarColor(lightColor.ToPlatform());
#pragma warning restore CA1422}}}
#endif
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I want the modern android app look where the content background ist the same as the status bar background and it adapts depending on dark and light mode. To achieve this I tried using the CommunityToolkit StatusbarBehaviour from C# code to dynamically adjust but at the moment it works for a brief moment at the start of the app and then it switches to the primary color of the colors.xaml.
Does anyone know a reliable solution to implement this basic feature in a .NET MAUI app?
Here is my workaround I tried to use in AppShell.xaml.cs:
Beta Was this translation helpful? Give feedback.
All reactions