Issue
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.
Solution
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);
Answered By - Carl Fletcher
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.