Stack Overflow archive
2 scoreaccepted

AppCompat toolbar's colorControlNormal is getting cached

score
2
question views
1.2K
license
CC BY-SA 3.0

Why is this happening?

Drawables share a ConstantState when created from a resource and AppCompat uses setColorFilter to backport tinting. So, when you open a new Activity, TintManager sets a ColorFilter on the Drawable which updates all instances of that drawable.

What's the best way to fix it?

If you want to make this drawable updatable without affecting other instances then you must mutate that existing constant state using drawable.mutate()

This should really be addressed in the library. Edit: It has been fixed internally.

For a dirty fix, do this in onResume()

java
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);

More info:

https://code.google.com/p/android/issues/detail?id=78289

http://www.curious-creature.com/2009/05/02/drawable-mutations/

http://developer.android.com/reference/android/graphics/drawable/Drawable.html#mutate()

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.