1

I have this button in my layout:

<Button
   android:id="@+id/followers_right"
   android:drawableLeft="@drawable/ic_team"
   android:text="@string/visibility_right_followers" />

By default, all my icons are grey. But in some cases, I want to apply a specific color. And for the drawable button, how can I do that programmatically ?

myButton.setColorFilter(getResources().getColor(R.color.tint_selected));

This line doesn't work (build error).

Thanks for your help!

anthony
  • 7,653
  • 8
  • 49
  • 101

1 Answers1

0

I tried to find a solution myself for this interesting question but I am not there yet. One work around is have the same icon in different colors as Drawable resources,

and change the icon of the button grammatically,

yourButtom.setCompoundDrawablesWithIntrinsicBounds(R.drawable.low, 0, 0, 0); 

But the only issue is, if you want huge range of color chages

diyoda_
  • 5,274
  • 8
  • 57
  • 89