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
  • 34,719
  • 24
  • 185
  • 251
Aurimas Deimantas
  • 561
  • 1
  • 6
  • 26

1 Answers1

0

Use AppCompatImageView which has setImageDrawable() method.

Diego Torres Milano
  • 61,192
  • 8
  • 106
  • 129
  • 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