Skip to content
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

Splashscreen and Dark/Light theme behavior changed on Android #25693

Open
AlleSchonWeg opened this issue Nov 5, 2024 · 1 comment
Open

Splashscreen and Dark/Light theme behavior changed on Android #25693

AlleSchonWeg opened this issue Nov 5, 2024 · 1 comment
Labels
t/bug Something isn't working

Comments

@AlleSchonWeg
Copy link

AlleSchonWeg commented Nov 5, 2024

Description

Hi,
something changed with Splashscreens and dark/light theming. I don't know when but i'm sure i had this working in my app. I use the Xamarin.AndroidX.Core.SplashScreen 1.0.1.12 nuget, because i need to display the splash a little bit longer and different colors for dark/light theme.

What i did:
In my csproj file i removed the MauiSplashScreen section.
In Platforms/Android/Resources i created values and values-night folder with styles.xml and colors.xml
In MainActivity.cs i set:
[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
In MauiProgram.cs i call installSplashScreen:

                                .UseMauiApp<App>()
                                .ConfigureLifecycleEvents(events =>
                                {
#if ANDROID
                                    events.AddAndroid(android => android
                                    .OnCreate((activity, bundle) =>
                                    {
                                        AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(activity);
                                    }));
#endif
                                })

If i run the app the colors in the splashscreen are correct. Depending what i set in styles.xml/colors.xml and if device is in dark/light mode.
For example my styles.xml in values-night for dark mode:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Test.Theme" parent="Maui.MainTheme.NoActionBar">
    <item name="android:windowLightNavigationBar">false</item>
    <item name="android:windowLightStatusBar">false</item>
    <item name="android:statusBarColor">@color/appColor</item>
    <item name="android:navigationBarColor">@color/appColor</item>
    <item name="android:windowBackground">@color/background</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:windowTranslucentStatus">false</item>

  </style>
  <style name="Theme.Splash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/background</item>
    <item name="windowSplashScreenAnimationDuration">200</item>
    <item name="postSplashScreenTheme">@style/Test.Theme</item>
    <item name="android:windowLightNavigationBar">false</item>
    <item name="android:windowLightStatusBar">false</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
  </style>
</resources>

And my colors.xml in values-night:

<resources>
  <color name="colorPrimary">#0bbd8b</color>
  <color name="colorPrimaryDark">#0bbd8b</color>
  <color name="colorAccent">#0bbd8b</color>
  <color name="appColor">#0bbd8b</color>
  <color name="background">#0bbd8b</color>
</resources>

$${\color{#0bbd8b}0bbd8b \space is \space this \space color}$$

This is the SplashScreen in dark-mode:
Image
The colors are correct. Butt problem is, when i switch the device from dark to light theme via system settings and the app is running the colors for statusBarColor and navigationBarColor are not changed to the values i set in Android/Resources/values/colors.xml. I have to restart the app to change the colors. Same happens if i change from light to dark mode.
The screenshot shows after changing from dark to light. StatusBar and NavigationBar are have still the dark theme colors:
Image

I'm sure that this worked some time ago.

Steps to Reproduce

Open sample app
Change device theme
Go back to app
Statusbar and Navigationbar should changed the colors.

MauiApp14.zip

Link to public reproduction project repository

No response

Version with bug

8.0.92 SR9.2

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

@AlleSchonWeg AlleSchonWeg added the t/bug Something isn't working label Nov 5, 2024
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant