Majid Hojati Majid Hojati - 1 month ago 9
Java Question

Add Image overlay on ImageView with custom color

I have an ImageView. I want to add a transparent overlay on top of it, but I have no idea how to do it. For example this is my image:

enter image description here

I want to add my overlay on it so it looks like this:
enter image description here

As you can see there is a black overlay on it, the point is that I want to make this overlay customizable and its color must change. I don't know even which keywords I should search in order to find a good result.

Answer

shader.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#00000000"
        android:centerColor="#7d000000"
        android:endColor="#7d000000"
        android:dither="true"
        />
</shape>


<ImageView

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/bla2" />

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/shader"/>

I think this is what you mean, you'll have to play with the gradient a little to get it the exact same way you want

Comments