2

I want to add a transparent overlay to my background image in Android, like below

enter image description here

My code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.bykar.bykar_provider.WaitingForActivationActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription=""
        android:scaleType="centerCrop"
        android:src="@drawable/map_bg"
        tools:ignore="ContentDescription" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        />
</RelativeLayout>
byteC0de
  • 5,153
  • 5
  • 33
  • 66
  • Did i write something wrong?I test your code and it worked in my android studio.So I posted that answer?can I know the reason for my answer not right? – Sharath kumar Sep 08 '17 at 10:39

2 Answers2

12

Add the background to view as 20% opaque

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#26000000"/>

Here are the opacity values if you need:

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
Sharath kumar
  • 4,064
  • 1
  • 14
  • 20
5

Just add opacity to the background color. On this example if you wish to add 70% opacity to your black color then change the background color to the hex code #B3000000

If you want a list of HEX transparency codes just check this answer

João Magalhães
  • 2,785
  • 2
  • 13
  • 17