slybloty
slybloty

Reputation: 6506

Modify existing theme

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.

Upvotes: 1

Views: 2878

Answers (2)

slybloty
slybloty

Reputation: 6506

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.

Upvotes: 2

Cat
Cat

Reputation: 67502

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.

Upvotes: 6

Related Questions