13

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

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Vivek Coder
  • 139
  • 1
  • 1
  • 5

7 Answers7

19

Try this:

android:background="@null"

Tyler MacDonell
  • 2,609
  • 18
  • 27
12

you can also set it in your java file like this:

 view.setBackgroundColor(Color.TRANSPARENT);
Preet_Android
  • 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
5

Try this as colour code

android:background="#00000000"
Sheraz Ahmad Khilji
  • 8,300
  • 9
  • 52
  • 84
4

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

Amit Modak
  • 169
  • 3
  • 8
1

Try this

android:background="#0000"
Madhuri
  • 368
  • 1
  • 10
1

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"
Gracie
  • 190
  • 1
  • 10
0

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.

lakimens
  • 35
  • 10