I have several styles in the app.
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="toolbarStyle">@style/Toolbar</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> <item name="colorAccent">@color/accent</item> </style> <style name="GreenStyle"> <item name="colorPrimary">@color/primary_green</item> <item name="colorPrimaryDark">@color/primary_green_dark</item> </style> <style name="BrownStyle"> <item name="colorPrimary">@color/primary_brown</item> <item name="colorPrimaryDark">@color/primary_brown_dark</item> </style> <style name="TealStyle"> <item name="colorPrimary">@color/primary_teal</item> <item name="colorPrimaryDark">@color/primary_teal_dark</item> </style> <style name="AppTheme.Main.Green" parent="GreenStyle" /> <style name="AppTheme.Main.Brown" parent="BrownStyle" /> <style name="AppTheme.Main.Teal" parent="TealStyle" />
When activating, I set the theme selected in the settings, for example:
setTheme(R.style.AppTheme_Main_Green); setContentView(R.layout.activity_weather);
Here is an excerpt from colors.xml
<color name="accent">#FFC107</color> <color name="primary_green">#4CAF50</color> <color name="primary_green_dark">#388E3C</color> <color name="primary_brown">#795548</color> <color name="primary_brown_dark">#5D4037</color>
The colors of the elements on the activation are set correctly, everything is fine. However, if I want to manually repaint an element and refer to the primaryColor property, the system takes the primaryColor color not set in my style, but from the default colorPrimary. In my case it is blue.
I appeal like this:
setFillColor(ContextCompat.getColor(context, R.color.colorPrimary));
or so:
<gradient android:angle="90" android:startColor="@color/colorPrimary" android:endColor="@color/accent" />
The @ color / accent call works correctly, since it is defined in the colors.xml file
However, if you refer to the accent color through @ colors / colorAccent, then the accent color also resets to the default color, and the color from my style is not used.
How to work with colors through "colorAccent" and "colorPrimary" so that they cling from my style?
Thanks in advance for your help.