How to darken an ImageView in Android to increase contrast

0

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
0

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.

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
         <ImageView
                android:id="@+id/rest_image"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />
             <View
                android:id="@+id/overlay_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background=“@color/yourColorWithAlpha" />
         </FrameLayout>

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.

<ImageView
            android:id="@+id/item_image"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_300sdp"
            android:scaleType="centerCrop"
            android:tint="#6F000000"
            android:src="@drawable/pasta"/>

Below is an image that has been darken

Answered question