android-styling.md

August 9, 2024 ยท View on GitHub

Android Styling

To use the features documented here, you need to use version >= 8.2.0 and a Expo Development build.

Make changes as documented below and then run the following commands to see the updated colors:

  • npx expo prebuild -p android --clean (apply configuration to the native code)
  • expo run:android (build the native code)

Configuration in app.json / app.config.js

{
  "expo": {
    "plugins": [
      [
        "@react-native-community/datetimepicker",
        {
          "android": {
            "datePicker": {
              "colorAccent": {
                "light": "#FF5722"
              },
              "textColorPrimary": {
                "light": "#FF5722"
              }
            },
            "timePicker": {
              "background": {"light": "#FF5722", "dark": "#383838"},
              "numbersBackgroundColor": {"light": "#FF5722", "dark": "#383838"}
            }
          }
        }
      ]
    ]
  }
}

It's not possible to specify a color only for dark mode. If you wish to influence dark mode color you must declare a value for both the light and dark modes. Plugin will throw an error otherwise. Plugin also validates that the color names you specify (e.g. textColorPrimary) are valid.

Configurable properties

The following illustrations show the different styles that can be applied to the date and time pickers.

DatePickerDialogTimePickerDialog
Date picker dialog breakdownTime picker breakdown

DatePickerDialog

PropertyAttribute Name
colorAccentcolorAccent
colorControlActivatedcolorControlActivated
colorControlHighlightcolorControlHighlight
selectableItemBackgroundBorderlessandroid:selectableItemBackgroundBorderless
textColorandroid:textColor
textColorPrimaryandroid:textColorPrimary
textColorPrimaryInverseandroid:textColorPrimaryInverse
textColorSecondaryandroid:textColorSecondary
textColorSecondaryInverseandroid:textColorSecondaryInverse
windowBackgroundandroid:windowBackground

TimePickerDialog

PropertyAttribute Name
backgroundandroid:background
headerBackgroundandroid:headerBackground
numbersBackgroundColorandroid:numbersBackgroundColor
numbersSelectorColorandroid:numbersSelectorColor
numbersTextColorandroid:numbersTextColor