0

I am importing a built-in Vector Asset in Android Studio and all of those are black in color. I am using the Vector asset on a button using android:drawableLeft ,but I want to change the color of the Vector asset from black to white. I have tried the solution here:
Change fill color on vector asset in Android Studio

But using android:tint doesn't work (because I think it might be for the button itself, not the button's drawable) and android:drawableTint doesn't work either , it gives me a rendering error and an exception in the preview window itself.
Exception raised during rendering: android.graphics.drawable.VectorDrawable_Delegate.nCreateTreeFromCopy(JJ)J

Community
  • 1
  • 1
Shailesh
  • 2,116
  • 4
  • 28
  • 48
  • 1
    You can change the color from generated XML file which is in drawable folder. – Developer Oct 18 '16 at 07:46
  • are you using `support-vector-drawable`? or you want to support 5+ devices only (API 21+)? – pskink Oct 18 '16 at 07:55
  • @pskink No, I am just using a `Vector Asset` that I get from right clicking on Drawables > New > Vector Asset. Should I be using something else ? I thought using vector would give me an advantage of not having to choose multiple images for different resolutions. Please correct me if I am wrong. My min SDK version is 4.2 (17) – Shailesh Oct 18 '16 at 08:01
  • 1
    so you have to use `support-vector-drawable`, for more read: https://developer.android.com/studio/write/vector-asset-studio.html, *"""Android 4.4 (API level 20) and lower doesn't support vector drawables. If your minimum API level is set at one of these API levels, you have two options when using Vector Asset Studio: generate Portable Network Graphic (PNG) files (the default) or use the Support Library."""* – pskink Oct 18 '16 at 08:04

1 Answers1

3

First of all, If you use vector on drawableLeft, drawableRigth, etc.. ,Vectors will crash your application for pre-lollipop devices. You can use this : https://github.com/bsobe/vectorview

Also, You can change hex colors in xml of the vector asset manually.

Barış Söbe
  • 470
  • 4
  • 7
  • Vectors can be used pre-lollipop with `app:srcCompat ` property. http://android-developers.blogspot.in/2016/02/android-support-library-232.html – jitinsharma Oct 18 '16 at 07:47
  • I am talking about android:drawableLeft property. – Barış Söbe Oct 18 '16 at 07:49
  • there is absolutely no need for any custom `TextView`s, you can simply call `setCompoundDrawables` – pskink Oct 18 '16 at 08:12
  • Are you sure calling setCompoundDrawables is enough to use vector on android:drawable left for pre-lollipop devices? Are you tried on pre lollipop devices? – Barış Söbe Oct 18 '16 at 08:16
  • you can call `setCompoundDrawables` with any `Drawable` you want, `VectorDrawable` extends `Drawable` so you can use it in that method – pskink Oct 18 '16 at 08:20
  • Are you talking about set drawables on Activity, etc..? Bec yes, you can set drawables without exception on Activity. I am talking about android:drawableLeft property. – Barış Söbe Oct 18 '16 at 08:26
  • i am talking about `TextView#setCompoundDrawables` method: instead of some third party custom views simply use that method – pskink Oct 18 '16 at 08:45
  • Okey, you right. However, you should handle all vectors onCreate (Activity, CustomView, Fragment..) and set via `TextView#setCompoundDrawables`. – Barış Söbe Oct 18 '16 at 08:48