Normally you would use the OnColor
like this
<Switch x:Name="optionSwitch" HorizontalOptions="StartAndExpand" OnColor="Blue" ThumbColor="Cyan" />
to customize the track color and you get the following result:
But in my application the OnColor
is always overwritten and I don't know the cause for this (something in Theme.Material.Light.DarkActionBar
?).
This is the look and feel in my app with the same code:
So the track color is not the color I set. It seems that there is an "effect", which modifies the color. I thought I could use a custom renderer and change the values for TrackTintMode
:
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Switch> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.TrackTintMode = Android.Graphics.PorterDuff.Mode.SrcOver;
}
}
But with this the off color is also set and on re-enabling it goes back to default. I tried many other things but the post would get very long with this ...
How can I turn this "feature" off?
Edit:
After many tries I think I can reproduce the issue. The MainActivity.cs
has to look like this:
[Activity(Label = "TestSwitch", Icon = "@mipmap/icon", Theme = "@style/AppTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
// ...
}
And the according theme in styles.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
</style>
</resources>
The rest is based on the default XF template.