Topics: Ability to choose a topic?

I would like to be able to post some topics to easily change the look of my application. Therefore, I understand that you can define a style that inherits from android: Theme, and then define the attributes inside that.

But two questions:

  • What if I want to have, say, more than one background color for different representations in the application? So I can have, say, a background for all activities and a different background for text presentations in action and a different background for buttons, etc. But then the theme depends on these (different) colors?
  • Is it possible to define a set of drawings, which depends on the theme used. I mean the same way you can define different drawings for different screen densities, for example. Ideally, I would have images with different color schemes used for different themes. Is it possible to determine this behavior in android?

Thanks for your help, James.

+5
source share
1 answer

You can simply define different styles for the different colors or drawings needed for each type of widget, and refer to those of your various themes. For instance:

<!-- themes -->

<style name="MyTheme" parent="android:style/Theme.Light">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@drawable/something</item>
    <item name="android:buttonStyle">@style/MyButton</item>
</style>

<style name="MyTheme.Red">
    <item name="android:buttonStyle">@style/MyButton.Red</item>
</style>

<style name="MyTheme.Blue">
    <item name="android:buttonStyle">@style/MyButton.Blue</item>
</style>

<!-- styles -->

<style name="MyButton" parent="android:style/Widget.Button">
    <item name="android:background">@drawable/btn_mydefault</item>
</style>

<style name="MyButton.Red">
    <item name="android:background">@drawable/btn_red</item>
</style>

<style name="MyButton.Blue">
    <item name="android:background">@drawable/btn_blue</item>
</style>
+3
source

All Articles