In order to get the proper native colors on android, there is some modification needed. The reasoning for this is to apply the native android shadowing on the off value of the ToggleSwitch, and proper focus shadow colors when
ToggleSwitch
es are clicked.
-
Open
Resources/values/Styles.xml
inside the.Droid
project. And, add two<item>
s to under theAppTheme
:- colorControlActivated: the on color for your ToggleSwitches thumb
- colorSwitchThumbNormal: the off color for your ToggleSwitches thumb)
you may add your colors here directly, for example #ffffff, or by files (see our example code below)
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- Color style for toggle switch --> <item name="colorControlActivated">@color/MaterialPrimaryColor</item> <item name="colorSwitchThumbNormal">@color/MaterialSurfaceVariantColor</item> </style> </resources>
-
(optional) If your application uses Light/Dark color palettes.
- Inside the
Styles.xml
file change theAppTheme
's parent toTheme.Compat.DayNight
:-<style name="AppTheme" parent="Theme.AppCompat.Light"> +<style name="AppTheme" parent="Theme.AppCompat.DayNight">
- Create a file named
colors.xml
underResources/values
. And, include your "Light" theme colors:<?xml version="1.0" encoding="utf-8" ?> <resources> <color name="MaterialPrimaryColor">#5B4CF5</color> <!-- SurfaceColor --> <color name="MaterialSurfaceVariantColor">#FFFFFF</color> </resources>
- Create a folder named
values-night
underResources/
- Create a file named
colors.xml
underResources/values-night
And, include your "Dark" theme colors:<?xml version="1.0" encoding="utf-8" ?> <resources> <color name="MaterialPrimaryColor">#B6A8FB</color> <!-- A variant of OnSurfaceMediumColor without alpha opacity (can't use alphas with android colors) --> <color name="MaterialSurfaceVariantColor">#808080</color> </resources>
- Inside the
-
(optional) If you have changed the material color palette for your application. Make sure these colors are updated as well in
ColorPaletteOverride.xaml
:MaterialToggleSwitchButtonColor
: knob color when unchecked (IsOn=false)MaterialSurfaceVariantLightColor
: knob color when checked (IsOn=true)MaterialToggleSwitchBackgroundColor
: Rail fill color when checkedMaterialPrimaryVariantLowThumbColor
: Knob color when the control is disabled
If your application uses
DatePicker
and/orTimePicker
(these are native components). To apply your material colors to these android components, do the following (this will affect everyDatePicker
/TimePicker
in the application).
-
Open
Resources/values/Styles.xml
inside the.Droid
project. And, add two<item>
s to under theAppTheme
:- datePickerDialogTheme
- timePickerDialogTheme
And add a new
<style>
as shown below:<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- Color style for Time/Date Pickers --> <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> <item name="android:timePickerDialogTheme">@style/AppCompatDialogStyle</item> </style> <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog"> <item name="colorAccent">@color/MaterialPrimaryColor</item> </style> </resources>
-
(optional) If your application uses Light/Dark color palettes.
- Inside the
Styles.xml
file change theAppTheme
's parent toTheme.Compat.DayNight
:-<style name="AppTheme" parent="Theme.AppCompat.Light"> +<style name="AppTheme" parent="Theme.AppCompat.DayNight">
- Create a file named
colors.xml
underResources/values
. And, include your "Light" theme colors:<?xml version="1.0" encoding="utf-8" ?> <resources> <color name="MaterialPrimaryColor">#5B4CF5</color> </resources>
- Create a folder named
values-night
underResources/
- Create a file named
colors.xml
underResources/values-night
And, include your "Dark" theme colors:<?xml version="1.0" encoding="utf-8" ?> <resources> <color name="MaterialPrimaryColor">#B6A8FB</color> </resources>
- Inside the