Search code examples
androidimageandroid-layoutandroid-imageviewandroid-view

Make ImageView have dark transparency


I want to add the transparent black color on top of the image and make it darker.

enter image description here

          <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/rest_image"
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:adjustViewBounds="true"
                    android:scaleType="centerCrop"
                    />
            </RelativeLayout>

I can set the alpha parameter but the color change is in white. I want to make the darker image like this. How can i do it in xml or Java code. I will set it based on condition.?

Thanks.


Solution

  • What you need is called tinting. Apply a tint to your ImageView:

    <ImageView
        ...
        app:tint="#6F000000"
        />