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


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -