5

I need to make my custom dialog transparent.

How can I do that?

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Hardik Gajjar
  • 5,038
  • 8
  • 33
  • 51

4 Answers4

10

You can also use following line in constructor

getWindow().setBackgroundDrawable(new ColorDrawable(0));
Tarun Nagpal
  • 964
  • 1
  • 9
  • 25
9

Hey budy. . . Use the xml file for Background that in Available in the developer site and Set #00000000 as the Background colour thats for the Transperent colour.

  • 4
    For some reason you can run into graphical glitches if you use `#00000000`. I recommend using `@android:color/transparent`. Don't ask me why since they are the same ARGB value, just trust me that I have run into problems with it. – Tyler Dec 08 '11 at 17:08
  • @Styler where would I add this `@android:color/transparent` line? in the xml-file for the dialog or in a style? been trying `android:background="@android:color/transparent"` but I suspect Im not doing it right. Mostly since its not working ^^ – Green_qaue Sep 27 '12 at 23:17
2

To make the background of the Dialog transparent you just need to set the theme of dialog to be android.R.style.Theme_Translucent_NoTitleBar. eg:-

new AlertDialog.Builder(context, android.R.style.Theme_Translucent_NoTitleBar).show();
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
EEJ
  • 678
  • 5
  • 12
0

You can set background color to Color.Transparent

NujnaH
  • 173
  • 1
  • 8
  • to setBackgroundDrawable you would need a ColorDrawable and in this case @Tarun Nagpal has the correct way of doing this. – Codeversed May 18 '12 at 02:38