0

Very common problem with a twist to which I couldn't find a solution for. I am setting my vector programmatically. I want to be able to change the tint color programmatically too. Found some solutions such as Programmatically tint a Support Vector

ImageView iv = ....
Drawable d = VectorDrawableCompat.create(getResources(), R.drawable.ic_exit_to_app_24dp, null);
d = DrawableCompat.wrap(d);
DrawableCompat.setTint(d, headerTitleColor);
iv.setImageDrawable(d);

The main problem comes with

iv.setImageDrawable(d);

I found that prelolipop only accepts setting view's drawable with

iv.setImageResource(int resource)

I couldn't find any solutions for setting it with a drawable file.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Aurimas Deimantas
  • 671
  • 1
  • 10
  • 29

1 Answers1

0

Use AppCompatImageView which has setImageDrawable() method.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Actually problem was in setting up drawable properly. If using Drawable vectorIcon = VectorDrawableCompat.create(view.getResources(), vectorDrawableSource, themeSource); It works just fine! Thank you! – Aurimas Deimantas Sep 12 '17 at 07:26