Different colors for Light and Dark theme from system #377
-
Currently, the theme transitions correctly if the theme is specified via XML without a specified I want to replicate that behavior, except I want to have different colors per dark and light themes. As an example, note how the primary color changes for a dark theme in the material guidelines. Is there an official way of doing this, perhaps through resource overrides? If not, is there a workaround? This is similar to #247, but the solution there only works for fully-bespoke in-app selection of themes. I want to customize the behavior based on the system theme. (Although I'm not sure how the first provided solution on that answer works for light/dark themes, so maybe that's the answer.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Answered my own question. This is how to replicate the behavior of public override void OnFrameworkInitializationCompleted()
{
base.OnFrameworkInitializationCompleted();
if (PlatformSettings is IPlatformSettings settings)
{
settings.ColorValuesChanged += PlatformSettings_ColorValuesChanged;
SetupTheme(settings.GetColorValues());
}
}
private void PlatformSettings_ColorValuesChanged(object? sender, PlatformColorValues colors)
{
SetupTheme(colors);
}
private void SetupTheme(PlatformColorValues colors)
{
if (colors.ThemeVariant == PlatformThemeVariant.Dark)
{
this.LocateMaterialTheme<MaterialThemeBase>().CurrentTheme = Theme.Create(
Theme.Dark,
myPrimaryColor,
mySecondaryColor
);
}
else
{
this.LocateMaterialTheme<MaterialThemeBase>().CurrentTheme = Theme.Create(
Theme.Light,
myPrimaryColor,
mySecondaryColor
);
}
} |
Beta Was this translation helpful? Give feedback.
Answered my own question. This is how to replicate the behavior of
MaterialTheme
usingMaterialThemeBase
.