An Expo Config Plugin to programmatically modify the native Android styles.xml
file during the prebuild process.
npm install expo-config-plugin-android-styles
# or
yarn add expo-config-plugin-android-styles
Sometimes you need to customize native Android theme attributes that aren't directly exposed via React Native component props or standard Expo config options. Manually editing files in the android
directory is discouraged in Expo managed projects.
Common examples include:
- Changing the accent color of native dialogs like the DatePicker or TimePicker.
- Setting a default
android:windowBackground
. - Overriding specific theme items for
AppTheme
or other styles.
This config plugin uses Expo's withAndroidStyles
modifier to safely add or modify <item>
tags within specified <style>
tags in your android/app/src/main/res/values/styles.xml
file.
- Tested with Expo SDK 48+
- Requires
@expo/config-plugins
>= 7.0.0 (this is a peer dependency that should be provided by your Expo project) - Requires
expo-build-properties
for native modifications
{
"expo": {
"plugins": [
[
"expo-config-plugin-android-styles",
{
"styles": [
{
"styleName": "DialogDatePicker.Theme",
"itemName": "colorAccent",
"itemValue": "#8f78aa",
"parentTheme": "Theme.AppCompat.Light.Dialog"
},
{
"styleName": "AppTheme",
"itemName": "android:datePickerDialogTheme",
"itemValue": "@style/DialogDatePicker.Theme"
},
{
"styleName": "AppTheme",
"itemName": "android:timePickerDialogTheme",
"itemValue": "@style/DialogDatePicker.Theme"
}
]
}
]
]
}
}
const withAndroidStylesModifier = require("expo-config-plugin-android-styles");
module.exports = ({ config }) => {
return {
...config,
plugins: [
[
withAndroidStylesModifier,
{
styles: [
{
styleName: "DialogDatePicker.Theme",
itemName: "colorAccent",
itemValue: "#8f78aa",
parentTheme: "Theme.AppCompat.Light.Dialog",
},
{
styleName: "AppTheme",
itemName: "android:datePickerDialogTheme",
itemValue: "@style/DialogDatePicker.Theme",
},
{
styleName: "AppTheme",
itemName: "android:timePickerDialogTheme",
itemValue: "@style/DialogDatePicker.Theme",
},
],
},
],
],
};
};
The plugin accepts an options object with the following structure:
interface StyleConfig {
styleName: string; // The name of the style to modify/create
itemName: string; // The name of the item to add/modify
itemValue: string; // The value to set for the item
parentTheme?: string; // Optional parent theme for new styles
}
interface PluginOptions {
styles: StyleConfig[]; // Array of style configurations to apply
}
To customize the DatePicker and TimePicker accent color:
[
"expo-config-plugin-android-styles",
{
"styles": [
{
"styleName": "DialogDatePicker.Theme",
"itemName": "colorAccent",
"itemValue": "#8f78aa",
"parentTheme": "Theme.AppCompat.Light.Dialog"
},
{
"styleName": "AppTheme",
"itemName": "android:datePickerDialogTheme",
"itemValue": "@style/DialogDatePicker.Theme"
},
{
"styleName": "AppTheme",
"itemName": "android:timePickerDialogTheme",
"itemValue": "@style/DialogDatePicker.Theme"
}
]
}
]
This plugin hooks into the Expo prebuild process. It parses the existing styles.xml, allows you to programmatically add or modify style items using the configuration, and then writes the updated styles.xml back to the native android project directory.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License