1

Description

When attempting to change the color of a drawable that is on top of a dark background, I ran into an issue where the color would be slightly changed.

In the image below, you will see that the top view that has a white background has a dark blueish icon color, but the view below which is on top of a dark background has a light blueish color.

Image #1

The drawable colors should be consistent regardless of the background color of the containing view.

Code

    ImageView fairInfoEmailImageView = (ImageView) getView().findViewById(R.id.fairInfoEmailImageView);
    fairInfoEmailImageView.setColorFilter(dashboardIconColor, PorterDuff.Mode.MULTIPLY);

    ImageView fairInfoSurveyImageView = (ImageView) getView().findViewById(R.id.fairInfoSurveyImageView);
    fairInfoSurveyImageView.setColorFilter(dashboardIconColor, PorterDuff.Mode.MULTIPLY);

Note*: The below image is implemented by both the ImageView's drawables being white and then applying a MULTIPLY color filter with the overridden color.

Attempts

  • Attempted ColorFilters, Tints, etc, but I believe these are bringing the background color into the equation.

Question

Is there a way to dynamically change the color of a drawable without the use of a ColorFilter?

Feel free to ask for more code or any questions about the problem.

CJB
  • 90
  • 1
  • 6
  • 1
    Whats the minimum API level you are aiming for your APP?? – Tasos Sep 08 '16 at 02:39
  • 15. Thanks for asking. I will update the question. – CJB Sep 08 '16 at 13:28
  • 1
    To speed things up i suggest getting your icons here https://materialdesignicons.com/ where you could custom color them so have 2 copies. They are small in size so it wont impact the size of your app. I was asking about the min APi because from android 5x and ApI 20+ you can use Vector drawables so its easy to change the color by code. – Tasos Sep 08 '16 at 23:26
  • I forgot to mention -- check here also for a possible solution by code -- > http://stackoverflow.com/questions/20121938/how-to-set-tint-for-an-image-view-programmatically-in-android – Tasos Sep 08 '16 at 23:32
  • Thank you so much for your help Tasos, but these are actually Vector drawables. I've tried all the possible coloring methods, but the icon's are actually the same color (See Nick Yelito's answer below). You can verify by looking at the pixels. It was an optic illusion caused by the contrasting backgrounds lol. Thanks again for your comments. – CJB Sep 09 '16 at 03:33
  • check here for a possible solution http://stackoverflow.com/questions/32924986/change-fill-color-on-vector-asset-in-android-studio – Tasos Sep 09 '16 at 07:17

1 Answers1

0

Those two icons in your image are the same color. R19 G89 B116 according to MSPaint.

It is a bit of an optical illusion that makes the colors seem different with different backgrounds, but they are the same.

Nick Yelito
  • 77
  • 1
  • 10
  • Haha I believe it is. Double check it with the eye dropper tool but it came out the same for me – Nick Yelito Sep 09 '16 at 02:32
  • 1
    Verified. Sigh. I was ripping my hair out over an illusion. Thank you for pointing it out. I upvoted your answer. – CJB Sep 09 '16 at 03:31