How to have a selector of vector drawables?
As it seems, this is a bug in the way the support library works, and it's not documented in any way.
I've tried to post a bug report about it, but Google marked it as UserError
, even though I don't see it documented, or have any kind of warning:
Working as intended. Vectors are not supported in containers unless you turn on AppComaptDelegate.setCompatVectorFromResourcesEnabled(true).
https://code.google.com/p/android/issues/detail?id=210745
So, if you see a selector that doesn't get shown, or that causes a crash with this log:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/selector.xml from drawable resource ID #0x7f02004f
you should either avoid using vectorDrawable
within a selector, or avoid using the vectorDrawables.useSupportLibrary=true line.
You could use AppComaptDelegate.setCompatVectorFromResourcesEnabled(true) , but according to the docs, this might be faulty (memory/performance issues, mainly) and is not recommended to be used at all:
Sets whether vector drawables on older platforms (< API 21) can be used within DrawableContainer resources.
When enabled, AppCompat can intercept some drawable inflation from the framework, which enables implicit inflation of vector drawables within DrawableContainer resources. You can then use those drawables in places such as android:src on ImageView, or android:drawableLeft on TextView.
This feature defaults to disabled, since enabling it can cause issues with memory usage, and problems updating Configuration instances. If you update the configuration manually, then you probably do not want to enable this. You have been warned.
Even with this disabled, you can still use vector resources through setImageResource(int) and it's app:srcCompat attribute. They can also be used in anything which AppComapt inflates for you, such as menu resources.
Please note: this only takes effect in Activities created after this call.