Invalid drawable tag vector

后端 未结 14 1072
小蘑菇
小蘑菇 2020-12-28 12:34

Im trying to use vector drawables on pre lollipop devices. I did all as instructed here but i still get this crash.

build.gradle:

14条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 12:46

    I faced a similar problem and @pedja's own answer is useful. More generally, as mentioned in Chris Banes's article on vector drawable compat, the support library works by injecting its version of ImageView over the system one on pre-L via some hooks. This implicitly requires the AppCompat versions of classes, such as AppCompatActivity, be used.

    In my case, the vector drawable is used in a standalone toast-like view without an associated activity, using the Application context. I ended up using AppCompatImageView in the xml layout definition directly, i.e. something like

    
    

    thus there is no need for the magic "hook" mechanism. As tested this also works with the Activity class without the need of using AppCompatActivity. All the above was done without upgrading to 23.2.1, which addressed a different problem.

提交回复
热议问题