Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i change accent color (AppCompat) programmatically?

I have:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorAccent">@color/myColor</item>
</style>

But I want to allow the user to change the accent color. Can I do it with AppCompat?

like image 268
krystian71115 Avatar asked Jul 08 '15 21:07

krystian71115


1 Answers

No you can't, because the accent color is defined in the theme and themes are read-only in Android.

The only thing you can do is switch themes or set the color of each component manually.

Note: you can apply a theme to a portion of UI instead of the whole Activity in order to change the accent color (or other things) locally. To do so, you can use the android:theme attribute in your XML layout with the AppCompat library, or you can inflate a layout by providing a ContextThemeWrapper as context to your LayoutInflater.

like image 133
BladeCoder Avatar answered Oct 30 '22 10:10

BladeCoder