Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom styles of product flavors in Android Studio?

I have a module with several product flavors ('foo' in this example). The base theme (style) is defined within the module.

Now my idea was to modify this theme in every flavor, by adding a styles.xml in #flavor#/res/values/ folder and extend the style, as I did it before in Eclipse, using library project mechanism. But obviously the complete style is overriden. My intention was, that gradle is merging the files together correctly.

  • MyApp
    • app
    • src
      • main
        • java
        • res\values
          • main_styles.xml
      • foo
        • java
        • res\values
          • foo_styles.xml

main_styles:

<style name="Theme.Main" parent="android:Theme.Light">
    <item name="android:title">A title</item>
    <item name="android:subtitle">A subtitle</item>

</style>

foo_styles:

<style name="Theme.Main" parent="android:Theme.Light">
    <item name="android:background">@color/foo</item>
</style>

What I expect:

<style name="Theme.Main" parent="android:Theme.Light">
    <item name="android:title">A title</item>
    <item name="android:subtitle">A subtitle</item>
    <item name="android:background">@color/foo</item>
</style>

What I get:

<style name="Theme.Main" parent="android:Theme.Light">
    <item name="android:background">@color/foo</item>
</style>

Any advice?

like image 856
Philipp Nußbaum Avatar asked Oct 31 '22 17:10

Philipp Nußbaum


1 Answers

They'll only merge if they have the same name. Call them both styles.xml.

EDIT: It appears that you can't: https://groups.google.com/forum/#!topic/adt-dev/sQTsk35U7Ic

like image 178
Fifer Sheep Avatar answered Nov 15 '22 03:11

Fifer Sheep