VectorDrawable not rendering correctly on API 23

gitter picture gitter · Jul 4, 2016 · Viewed 10.9k times · Source

I am replacing all my icons with VectorDrawables wherever possible. But I noticed a couple of them don't render correctly on API 23 and the color seems to be bleeding out. One of these 3 renders fine. Here's a screenshot from a isolated project I created:

enter image description here

Looks perfectly fine on API 21:

enter image description here

The source code of sample app is here

I am using AppCompat 24.0.0, app:srcCompat on ImageView and have set vectorDrawables.useSupportLibrary=true. I also tried AppCompat 23.4.0 with target 23. However, if I remove appCompat and set minSdkVersion to 21 and use native vector support, the results don't change. The IDE doesn't complain of anything being unsupported. How do I figure out what's the problem? Is it a platform bug? Are there any workarounds?

Answer

Luke picture Luke · Sep 18, 2017

I had exactly the same problem on API 23 only. I was setting my ImageView source dynamically, rather than in xml. I realised the problem was that I was doing:

Drawable show = getContext().getResources().getDrawable(resourceId);

When I should have been doing:

Drawable show = AppCompatResources.getDrawable(getContext(), resourceId);

I hope this helps someone!