Attribute of RelativeLayout android:background="@android:color/transparent"
is not working . I just want to make its background transparent?

- 29,392
- 25
- 90
- 143

- 139
- 1
- 1
- 5
7 Answers
Try this:
android:background="@null"

- 2,609
- 18
- 27
-
7Sorry it dint worked. No Brother i want a transparent background so that my background activity will be visible at the back. – Vivek Coder Apr 02 '13 at 05:42
-
@VivekCoder Sorry, then I'm not exactly sure what you mean. Could you show us a picture of the problem? – Tyler MacDonell Apr 02 '13 at 06:41
-
@Vivek Coder: Can you please share the solution? I am also trying to make this work. – ARK Oct 25 '15 at 17:16
-
@Vivek Can you please share the solution? – Md. Sajedul Karim Nov 07 '15 at 16:10
you can also set it in your java file like this:
view.setBackgroundColor(Color.TRANSPARENT);

- 2,332
- 5
- 25
- 43
-
Thanx but its not good to set the properties of view programmatically. i need a solution without using styles.xml. I just want to set background property and make it transparent but i failed. – Vivek Coder Apr 02 '13 at 05:46
-
RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourrelativelayoutid); rl.setBackgroundColor(Color.TRANSPARENT); – Preet_Android Apr 02 '13 at 06:23
-
No No it wont work we have to set a theme through the style.xml which is the only ultimate solution for it. i failed to do this without using style. Solution is as follows: set this as the Theme of activity as: android:theme="@style/Theme.Translucent" we are done:) – Vivek Coder Apr 04 '13 at 04:48
-
i think above will help those who are indulged i this problem like me--keep on coding – Vivek Coder Apr 05 '13 at 04:00
-
When I use any other color ( say `setBackgroundColor(Color.RED)` ), it works just fine. but when I change it to transparent ( `setBackgroundColor(Color.TRANSPARENT)` ), it takes about 1 second to change the color. Any idea why this is happening ? – mrid Nov 28 '17 at 12:29
for your layout set
android:background="#00000000"
00 - Red
00 - Green 00 - Blue 00 - Opacity/Alpha....to specify transparency
for eg. :- #FF000050 will give you red color with 50% transparency

- 169
- 3
- 8
-
3Is this right? I think Android uses the first two as the alpha (#AARRGGBB), and the transparency is in hex, too, so 50% would be #7FFF0000. – David John Welsh Jul 31 '15 at 02:04
-
As @DavidJohnWelsh said `#FF000050` will NOT give you red color with 50% transparency. – mVck Nov 20 '17 at 18:09
-
Try this
android:background="#0000"

- 368
- 1
- 10
-
2
-
The valid syntax is #AARRGGBBAA AA = Alpha RR = Red GG = Green BB = Blue which should make a completely transparent black #00000000 – Nerudo Oct 23 '14 at 09:30
Just ran into the same situation. you could use this theme for your activity:
@android:style/Theme.Translucent
then set the view background color
android:background="@android:color/transparent"

- 190
- 1
- 10
Well, since you said you have an activity in the background, you should be using a fragment for this. If you're using a fragment, just set thr framelayout to transparent background, or don't set it at all, I think this should work as well, your fragment would be on top of the other layout.
If you use
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, fragment).commit();
Then it just adds it on top of the previous one, doesn't replace it like .replace() does. If you want an activity to be on top of another activity, that is not possible, as there can be only one activity alive at one time.

- 35
- 10