How to change current Theme at runtime in Android

Posted by Guido on Stack Overflow See other posts from Stack Overflow or by Guido
Published on 2010-03-20T11:36:41Z Indexed on 2010/03/20 11:41 UTC
Read the original article Hit count: 400

Filed under:
|

I've created a PreferenceActivity that allows the user to choose the theme he wants to apply to the entire application.

When the users selects a theme, this code is executed:

if (...) {
    getApplication().setTheme(R.style.BlackTheme);
} else {
    getApplication().setTheme(R.style.LightTheme);
}

But, despite I've checked with the debugger that the code is being executed, I can't see any change in the user interface.

Themes are defined in res/values/styles.xml, and Eclipse does not show any error.

<resources>
    <style name="LightTheme" parent="@android:style/Theme.Light">
    </style>

    <style name="BlackTheme" parent="@android:style/Theme.Black">
    </style>    
</resources>

Any idea about what could be happening and how to fix it? Thank you.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-themes