I have an app that can be styled for different customers. I use the styles.xml to style the app for each customer. However, I need to compile the app, every time I need to change the styles. I want to avoid this by getting these style definition from an outside file configuration, and then apply them at run time. I´m already doing this for other resources like images and texts/labels.
Is this possible? How?
Regards
CodePudding user response:
I'll give an example for a color.
If a style has <Setter Property="BackgroundColor" Value="{StaticResource Color1}" />
, then that refers to a Resource with key Color1
.
In App.xaml.cs, read the config, use it to construct a Color instance. then set that Resource:
Color color1 = ...;
Application.Current.Resources["Color1"] = color1;
CodePudding user response:
My issue is for example for resources like "android:colorPressedHighlight" that are specified in the styles.xml in the Android project.
The ColorPressedHighlight
field is const. It is Compile time constant and could not assign value at runtime.
MS official docs: https://docs.microsoft.com/en-us/dotnet/api/android.resource.attribute.colorpressedhighlight?view=xamarin-android-sdk-12