nhaarman nhaarman - 28 days ago 17
Android Question

How to _really_ programmatically change primary and accent color in Android Lollipop?

First of all, this question asks a very similar question. However, my question has a subtle difference.

What I'd like to know is whether it is possible to programmatically change the

colorPrimary
attribute of a theme to an arbitrary color?

So for example, we have:

<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#ff0000</item>
<item name="android:colorAccent">#ff0000</item>
</style>


At runtime, the user decides he wants to use
#ccffff
as a primary color. Ofcourse there's no way I can create themes for all possible colors.

I don't mind if I have to do hacky stuff, like relying on Android's private internals, as long as it works using the public SDK.

My goal is to eventually have the
ActionBar
and all widgets like a
CheckBox
to use this primary color.

Answer

Themes are immutable, you can't.