android - Apply ColorFilter to a Drawable inside a LayerDrawable -
i want have 2 cars in different colors (let's red , blue) displayed @ same time game , use same layerdrawable
(which set image resource imageview
) both cars:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/car_backstuff"/> <item android:drawable="@drawable/car_body"/> <item android:drawable="@drawable/car_frontstuff"/> </layer-list>
the problem when want color car, this:
_layerdrawable.getdrawable(1).setcolorfilter(color.red, porterduff.mode.multiply);_
but when second car (i.e color.blue
) both cars become blue !
i knew because refers same resource (r.drawable.car_body in case) want know if there way apply colorfilter
different each car insert layer on top of car body , multiply or ?
i answer own question:
the solution call mutate()
layerdrawable
, after changes on drawable
inside not repercuted other 1 use same resource, that's magic !
Comments
Post a Comment