Reputation: 37
I have a requirement to create an application in the below structure
Theme 1
Theme 2
and while building the application ( apk ), I can just change the themeType to ThemeOne/ThemeTwo and the application builds for that theme. I don't want to change this theme inside every activity/fragment.
for practical example: for banking apps, the applications will be developed once.
my themes are below
and Icici colors and their logos will be inside IciciTheme, the same applies to different themes. orange is the primary color for ICICI for the axis, it's kind of purple for sbi, it's blue.
It's not specifically about primaryColors. Each theme can have around 100 colors
I want to achieve this through Jetpack Compose, please share your ideas/ thought process of how to achieve this.
Upvotes: 1
Views: 716
Reputation: 2628
The best way to achieve this in Android using product flavors. Answering considering your practical example as reference. In specific resource folder, we can write specific dark and light theme variations for specific flavors.
You've to declare flavors for all type of variations you want to cover/deliver. please add below code to your build.gradle file which has android{ }
...
android {
...
productFlavors {
icici{
}
sbi{
}
axis{
}
}
sourceSets.icici{
res.srcDirs = ['res', 'src/icici/res']
}
sourceSets.sbi{
res.srcDirs = ['res', 'src/sbi/res']
}
sourceSets.axis{
res.srcDirs = ['res', 'src/axis/res']
}
}
This is right way of doing it considering modular way of maintaining code and future aspect of changes.
Upvotes: 2