android - Toolbar color does not stays the same -
i wanted change toolbar color programmatically, using code: ((appcompatactivity) getactivity()).getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.test))); i have 2 fragments, , b, suppose if switch a, color changes blue, if switch b, color changes test , again if switch , b, color stays blue! for color changes in both fragments using above code. above code trigger on oncreateview , problem think. how can make listener this, when fragment on screen each time , color changes? use getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.test))); and getsupportactionbar().setbackgrounddrawable(new colordrawable(getresources().getcolor(r.color.blue))); in activity not in fragments