ben Heo
ben Heo

Reputation: 141

Change color of an image in android

I wonder if there is a way to change the color of my image on the button easily, my simple example is like this,

CircleButton.setImageResource(android.R.drawable.ic_media_play);

I have a play audio icon (white) and want to change the icon color to red, like this

CircleButton.setImageResource(ColorChange(Red, android.R.drawable.ic_media_play));

What seems to be the easiest way for doing ColorChange() ?

Upvotes: 3

Views: 3082

Answers (1)

Libin
Libin

Reputation: 17085

Use ColorFilter to change the button image color. Your button should be ImageButton

Set the image resource to the ImageButton

CircleButton.setImageResource(android.R.drawable.ic_media_play);

And, change the image color when required like this

CircleButton.setColorFilter(getResources().getColor(R.color.any_color)); 

Refer : http://developer.android.com/reference/android/graphics/drawable/Drawable.html#setColorFilter(android.graphics.ColorFilter)

Upvotes: 6

Related Questions