Open MichaelRumpler opened 3 years ago
Hi,
same here so I confirm. I am using ConfigChanges.UiMode
and style.xml:
<style name="MainTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
Only changes to colors I made (ContentPage is not using any System default?!):
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark=Black, Light=White}"/>
</Style>
So it looks like "only" Android defined colors/themes are affected.
regards Daniel
@MichaelRumpler is mentioning kind of a workaround: Removing ConfigChanges.UiMode
makes your App automatically restarting on Dark/Light Mode switching. But if the user is currently interacting with the App this might annoy the user as hell ;)
@MichaelRumpler is mentioning kind of a workaround: Removing
ConfigChanges.UiMode
makes your App automatically restarting on Dark/Light Mode switching. But if the user is currently interacting with the App this might annoy the user as hell ;)
Especially when the device switches themes automatically at a specified time.
Any news on this? I have the same behaviour
@tuxmainy did you get anywhere with this?
It appears like Android does not change colors automatically when the theme changes. So you have to do it manually. @jamesmontemagno explained a workaround for the status bar in this video.
I doubt that the SwitchCell
in Xamarin.Forms will be fixed considering that MAUI is around the corner and most of the Forms team is already working on that. OTOH @jfversluis is back fixing Forms bugs and he implemented all the theme stuff, so we might get lucky.
@MichaelRumpler Thanks for getting back to me on this one!
From what I remember implementing this is that Android indeed needs to recreate the activity in order to apply all the colors successfully. So I doubt if we are able to make the colors in your colors.xml
work. I can look at the Forms specific stuff though :)
I would take a look at https://github.com/jamesmontemagno/MyCoffeeApp/ as an example. Has iOS in there as well.
Thanks for the response @jfversluis. I see. then we'll have to live with it... some native elemnts like pickers and such stay in "wrong" styling/theme. @jamesmontemagno Thanks. I like your videos a lot, Good job!!
@tuxmainy did you get anywhere with this?
Nope, just made my app restart on theme change
@tuxmainy make sure your configurationchanges are set correct in your main activity https://github.com/jamesmontemagno/MyCoffeeApp/blob/master/MyCoffeeApp/MyCoffeeApp.Android/MainActivity.cs#L20
You must add ConfigChanges.UiMode
Seeing same issue still. Is there a way to fix the issue with the switches? I am disabling dark mode while the device on dark mode, but the onclor of the switch isn't appears no matter which color it is set with. If I have a background for the switch or a diffrent color background on the screen I can see the full switch and not only the thumbnail, it is still barely visible, but I need a white background so it is not visible at all.
I want to keep my app running when the device changes between light and dark mode. So I added
ConfigChanges.UiMode
to theConfigurationChanges
in my MainActivity.Now the activity is not restarted anymore, but some colors are not applied. Mainly those which I specified in the files values/colors.xml and values-night/colors.xml. I have different colors in the values-night folder. This works fine when the app is restarted, but when the theme changes while it is already running, then these colors are not applied.
Here are screenshots from the sample app when it starts in light and dark mode:
When I change the theme, then they look like this:
I see four issues here:
<item name="android:statusBarColor">@color/statusBar</item>
in values/styles.xml with different colors in the colors.xml files. But these are not changed when the theme changes.SwitchCell
s do not have aTextColor
property. They seem to magically recognize the color when the app starts and render with light/dark text so that they are readable against the background. But when the theme changes, then the text color stays the same and you don't see the text anymore.android:tint="@color/white"
. This color is actually black in the dark theme, but the change is not applied.Issues 1 and 4 are very similar and may not have something to do with Xamarin.Forms at all. But maybe somebody can help me with these too. I already opened a question at StackOverflow, but nobody could help me there (yet).
But 2 and 3 are definitely Forms problems.
Most colors change fine when defined in XF. This all works in iOS like a charm.
Here is the source of the repro project: Repro_ChangeTheme.zip