codeMagic
codeMagic

Reputation: 44571

Create two separate themes in an app

I've been using custom styles and I was doing fine but now I'm confused on how to use completely different styles for widgets such as CompoundButtons, Spinners, ImageButtons, etc.. I have custom Buttons made for each type and each has its own drawable depending on its state. That I have gotten figured out but I need two completely different Themes (ex. use meal_orange ImageButton when state is pressed and use meal_blue for ImageButton state pressed for my other Theme) depending on which of two customers the app is for. I've searched for this problem so either it isn't possible without two separate apps or I'm not searching the right terms or fully understanding themes (possibly both).

A small example of what I currently have is in my styles.xml

// these point to separate selector files to show the different states
<style name="MealButton" parent="@android:style/Widget.ImageButton">
    <item name="android:background">@drawable/meal_button</item>
</style>

<style name="CatButton" parent="@android:style/Widget.ImageButton">
    <item name="android:background">@drawable/cat_button</item>
</style>

I originally created a custom theme with something like

<style name="CustomActivityTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

the ActionBar part is irrelevant because I created a custom bar but if I could do that and inside here dictate to use the above examples of the ImageButton styles then that would be great.

I hope I explained this correctly. Can someone tell me if this is possible. I can't imagine I would need two separate versions of the app but maybe. I thought I could declare these styles inside the different themes but I didn't seem to be able to do that for widgets.

Just to clarify, the question is how can I use that first chunk of code inside the second chunk and do that for two separate themes? Thanks!

Upvotes: 2

Views: 906

Answers (1)

Raghav Sood
Raghav Sood

Reputation: 82563

Unfortunately, this isn't possible.

App styles cannot be controlled programmatically app wide, so you can't really set a flag and have it work separately for each client.

You could perhaps have a bash script, or use maven, to automate the builds by swapping the XML files in and out on a per build basis.

Or if your codebase is exactly the same for both clients, you could move it into a library project, and create two projects that stem from it to have separate themes.

Upvotes: 2

Related Questions