Unable to change the background color(Accent) of DatePicker widget in Xamarin Forms Project for Android. TimePicker is working fine.
Here are the files I know to change. I've practically tried every possible solution. Xamarin Project is up to date. Tried on multiple devices , real and virtual.
Color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="launcher_background">#FFFFFF</color>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#004193</color>
<color name="colorAccent">#004193</color>
<color name="colorWhite">#FFFFFF</color>
</resources>
Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:textAllCaps">false</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MainTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
Custom Renderer
public class OKCancelDatePickerRenderer : DatePickerRenderer
{
public OKCancelDatePickerRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (Control != null) // also tried e.NewElement etc.
{
Control.SetBackgroundColor(Android.Graphics.Color.Blue);
Control.SetHighlightColor(Android.Graphics.Color.Orange);
Control.SetHintTextColor(Android.Graphics.Color.Green);
Control.SetLinkTextColor(Android.Graphics.Color.Yellow);
Control.SetOutlineAmbientShadowColor(Android.Graphics.Color.Red);
Control.SetOutlineSpotShadowColor(Android.Graphics.Color.DeepSkyBlue);
}
}
}