0

I am unable to change the color of my vector used in my button widget.

Below is my code:

<Button
    android:id="@+id/btnSearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Search"
    android:background="@color/blueButton"
    android:textColor="@color/white"
    android:drawableLeft="@drawable/ic_search"
    android:tint="@color/white"
    android:elevation="10dp"
    android:textSize="14sp" />

By adding tint, it is still showing me below result: enter image description here

Here is the vector code:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
<path
    android:fillColor="#FF000000"
    android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kamranbhatti585
  • 232
  • 2
  • 16

2 Answers2

7

Use android:drawableTint instead of android:tint.

Ben P.
  • 52,661
  • 6
  • 95
  • 123
1

Change:

 android:fillColor="#FF000000"

To:

 android:fillColor="@color/white"
Xenolion
  • 12,035
  • 7
  • 33
  • 48
  • No,I want to change it from Button XML. Because, if I want to use same search vector with diff colors in other layouts, then this will lead me to create more xml vectors with different colors. – kamranbhatti585 Oct 25 '17 at 21:34
  • @ben-p solved it. Take a look here https://stackoverflow.com/a/46942521/7746337 – kamranbhatti585 Oct 25 '17 at 21:46
  • 1
    Oooh I got it! All the best! I didnt know such an attribute exists. Lemme give him an upvote for really! – Xenolion Oct 25 '17 at 21:47
  • 1
    If you encounter any issue refer to here https://github.com/snodnipper/android-appcompat-issue198613 and also https://issuetracker.google.com/issues/37077118 but its a bit old may be already solved! **Happy coding!** – Xenolion Oct 25 '17 at 21:52
  • I will must take a look :) and gave you a +1 because your way is right somehow. – kamranbhatti585 Oct 25 '17 at 22:46