How to darken an ImageView in Android to increase contrast


I was designing an Android UI using ImageView. I got to a point where I need to darken the ImageView so that I will create a contrast between the image and text on the ImageView.

I have add the solution I found in the answer section.

Answered question

There are few ways you can use to darken an ImageView.

First solution

You can use a ViewGroup layout file that contains an ImageView with another View over-layered  above it.

In the overlayered view, the background color is set using 4 color channels. One of the channels will represents transparency.

The code below adds more detail to above explanation.

                android:scaleType="centerCrop" />
                android:background=“@color/yourColorWithAlpha" />

Second Solution 

This is simple. You can directly use ImageView backgroundTint property and as a black color with transparency to it. Below is a simple code snippet.


Below is an image that has been darken

Answered question