简体   繁体   中英

How to change application colors with Flavors in Android

In my application, I have 2 flavors , and I want to change the application's color ( res/color ) for each of this flavors !

Please see my code below at build.gradle file :

flavorDimensions "default"
productFlavors {
    app1 {
        applicationId "com.app.myApp1"
        resValue "string", "app_name", "App 1"
        manifestPlaceholders = [
                appIcon: "@drawable/logo_app1"
        ]
    }
    app2 {
        applicationId "com.app.myApp2"
        resValue "string", "app_name", "App 2"
        manifestPlaceholders = [
                appIcon: "@drawable/logo_app2"
        ]
    }
}

I don't know on setting the color.xml for each of this flavors !

How can this be possible?

Did you create a separate as below:

[Project Root]
  -[Module]
    -src
      -main
      -app1
        -res
          -drawable-*
            -logo_app.png
      -app2
        -res
          -drawable-*
            -logo_app.png

If you do it shold work on its own without needing to specify anything in the gradle file.

Article with no gradle file configuration: https://medium.com/@orafaaraujo/flavors-e01015eff979

Article with gradle file configuration: https://medium.com/@sgkantamani/android-product-flavors-eb526e35f9f1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM