1

I would like to know if it is possible (and how) to customize an existing theme.

What I'm looking for is how can I retrieve a certain attribute (i.e. color) and change it when the Activity starts and reapply the modified theme before setContentView().

Similar to setTheme(), but instead of using a resource id, use the modified theme.

slybloty
  • 6,346
  • 6
  • 49
  • 70

2 Answers2

6

Why not just make your own theme, setting the android:parent to the theme you want to copy, then set your own attributes? That is demonstrated in this documentation, like so:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>

In this case, the CodeFont style will be identical to the TextAppearance.Medium style, except for the items specified here. You can do the same with any theme, including the default Holo or Dark theme or whatnot.

Cat
  • 66,919
  • 24
  • 133
  • 141
  • Because I want to be able to change it every time the `Activity` starts using different input values. This way it's static. I've looked into it and tried it, but it's not what I want. – slybloty Sep 10 '12 at 19:19
  • 1
    You cannot change a style programmatically, sorry. You [can modify the appearance of items based on a custom style](http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view), but once the style is set in XML, it cannot be modified. – Cat Sep 10 '12 at 19:20
  • That also deals with preloaded styles. I'm looking for changing it while running. – slybloty Sep 10 '12 at 19:23
  • Well, as I've already given you the skinny--you cannot change styles or edit them programmatically--that's as far as the answer will go. Good luck, I guess. – Cat Sep 10 '12 at 19:29
2

Based on further research and Eric's comment there is not yet a possible way to modify a theme programmatically. Different themes can be applied programmatically but not modified. Once the style is set in XML, it cannot be modified.

slybloty
  • 6,346
  • 6
  • 49
  • 70