I have an app which uses android.support.v7.widget.Toolbar
. Every section of the app is a Fragment
accessed through a support.v4.widget.DrawerLayout
I need to change the Toolbar
color depending on which section is shown (client particular needs).
I defined some colors in the colors.xml
so I can make something like:
changeToolbarColor(R.color.section_one);
/**/
private void changeToolbarColor(int color_res_id){
Integer colorTo = getResources().getColor(color_res_id);
toolbar.setBackgroundColor(colorTo);
}
The problem is, once I do this, every view using the primaryColor
(the original primary color from the toolbar) now shows up using the new color of the Toolbar.
So if my Toolbar was green and I change it to red, now everything using the old green uses red instead.
I suspect, that the change of the Toolbars background changes the primaryColor
definition itself (which makes no sense to me). Because I have no other idea of how unrelated elements in unrelated activities start using the same color.
Is this a bug? Anyone with this problem? Any workarounds available?
Thanks for your help.
Palette
or any other approach? But I can't think of a propper way of doing it right now. – Eloi Navarro