JakeWharton / butterknife

Bind Android views and callbacks to fields and methods.
http://jakewharton.github.io/butterknife/
Apache License 2.0
25.56k stars 4.6k forks source link

Use AppCompatResources#getDrawable() under the hood #460

Closed ZacSweers closed 3 years ago

ZacSweers commented 8 years ago

Originally was here for requesting vector drawable support, but we can actually just use this method under the hood and support all variants in @BindDrawable

ZacSweers commented 8 years ago

Would presumably look like:

@BindVector(R.drawable.thing) AnimatedVectorDrawable thing;

Where the type could be inferred from the field type (allowing the annotation to work on any of the four permutations).

To kind of expand from this a bit, I've been wondering if BindDrawable should do this in general, where you can use it on any drawable and have it cast accordingly. Compat vectors would require special implementations though since they have separate creators.

ZacSweers commented 8 years ago

For anyone interested, I have a branch with this done: https://github.com/hzsweers/butterknife/tree/z/vector

consp1racy commented 8 years ago

Sticking to BindDrawable would be nice since it looks like AppCompat is able to support inflating anything even custom drawables.

And https://github.com/JakeWharton/butterknife/issues/461 of course.

ZacSweers commented 8 years ago

That's not feasible for support vector drawables since they require manual creation through the create() APIs. Animated vector drawables also have extra APIs over the usual drawable APIs that most people would want to use.

JakeWharton commented 8 years ago

Seems like we can do this with @BindDrawable now

ZacSweers commented 8 years ago

Yeah with AppCompatResources#getDrawable(). I'll edit the title/description :)

tyler-at-uv commented 7 years ago

I would like to up vote this issue - trying to use binding for VectorDrawableCompat. Thank you.