Math is Hard
Math is Hard

Reputation: 942

Completely change Android ImageView's color with tint color

Is there a way to completely change the color of an ImageView in Android? I tried using

imageView.getDrawable().setColorFilter(new  PorterDuffColorFilter(0xFFF7962F, PorterDuff.Mode.MULTIPLY));

and

imageView.setColorFilter(0xFFDDDDDD, PorterDuff.Mode.MULTIPLY);

on an ImageView with a gray image drawable but they only added a color on top of the existing gray making it look kind of weird.

On iOS you can do

[imageView setImage:[[UIImage imageNamed:@"my_image"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
imageView.tintColor = [UIColor redColor];

And it will completely remove whatever color was used to render the UIImageView and replace the "skeleton" image with the designated color. Perhaps it's because the tint always has an alpha transparency on it? I did specify 0xFF on the alpha part though.

Upvotes: 4

Views: 4542

Answers (1)

Carl Fletcher
Carl Fletcher

Reputation: 116

You're using the wrong blend mode, MULTIPLY combines both source colour and the colour you're adding. You probably want this:

imageView.setColorFilter(0xFFDDDDDD, PorterDuff.Mode.SRC_IN);

Upvotes: 10

Related Questions