Home > Software design >  android svg setting fillColor from colors.xml resource
android svg setting fillColor from colors.xml resource

Time:12-14

I have app with different flavors and I want to set the fillColor property of my SVG icons. Since I have multiple flavors, I have also multiple colors.xml files (for each flavor one). My first idea was to add one color (f.e. sideIconsColor) and then use this color as the fillColor for every icon. The problem is android is not capable of taking colors from colors.xml in SVG icons for API levels lower than 24. Now it looks for me that I have only one option: adding in every flavor resources folder the same SVG icon with only different color (f.e. #19457a. since I can not take colors from resources).

For me, this solution looks lousy and boilerplatish. So before implementing this, I would like to ask is there any other possible solution or this is my only option at the moment. Thanks!

CodePudding user response:

You don't have to change the color in svg resource. You should set the tint color of the ImageView (or any other view) programmatically or in XML layout file, this will automatically pick the right color from the current build flavor.

  • Related