简体   繁体   中英

Android drawable resources: how to change color scheme based on version of application

I am trying to implement two different versions of the same application, the only difference being the color scheme. How would I go about displaying different drawables based on the version?

For example, let's say I have a Blue version and a Red version. I would like to use the same source code for both but have an easy way to convert between the two color schemes. I am confused on how I would tell Android that I want to use the Blue version (or Red) and have it access files perhaps in resources/drawables/Blue or resources/drawables/Red. I found the link below, but I don't understand how I can implement this using just one package. Is it possible?

Dynamically change the name of the resource file to be used?

Making resources theme dependent

One way to do it is simply have a SharedPreferences int, where if it is 0, the app is in "red mode" and 1, it is in "blue mode". The downside of this is that you have to change the scheme in each activity.

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