31

I want to get rid of the border in my dialog box and make it look absolutly transparent, as if the image is on the top of screen.

enter image description here

My dialog xml is -

<?xml version="1.0" encoding="utf-8"?>

<ImageView android:id="@+id/ImageView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_centerHorizontal="true" android:visibility="invisible"/>

nasaa
  • 2,701
  • 8
  • 47
  • 76
  • possible duplicate of [Dialog with transparent background in Android](http://stackoverflow.com/questions/10795078/dialog-with-transparent-background-in-android) – yanchenko Jul 18 '13 at 21:57

7 Answers7

97

Try below code

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
  • Now a new problem has comeup. the entire screen flickers as described here - http://stackoverflow.com/questions/3379322/android-fullscreen-status-bar-flickers I was wondering if there is any workaround or if i can get the same effect without using the dialog? – nasaa May 20 '11 at 08:50
  • Tried that and still getting this issue. I made my Activity to go full screen as well thinking that it might work but it didn't/ – nasaa May 20 '11 at 09:10
  • I dont know if that works or will create the same problem try using Activity instead Dialog – ingsaurabh May 20 '11 at 09:13
  • Turn the animation of activity off and set the theme transparent in xml it will work as Dialog – ingsaurabh May 20 '11 at 09:16
  • And in the manifest this can be added to the activity's declaration: android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" and android:layout_gravity="center" - to the xml layout. – Yar Oct 06 '12 at 16:12
63

try this:

mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
Zsolt Safrany
  • 13,290
  • 6
  • 50
  • 62
20

To give a translucent effect, say 50% opacity, use:

Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
mDialog.getWindow().setBackgroundDrawable(d);

'130' can be changed (0-255) to acheive desired opacity.

ashish
  • 750
  • 5
  • 12
  • 1
    Or if you want a one liner, `mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0x88000000));` where the "88" is a hex value that controls the transparency (00 is completely transparent, FF is completely opaque). – RTF Jan 30 '14 at 18:25
10

try this:-

final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.splash);
dialog.show();
duggu
  • 37,851
  • 12
  • 116
  • 113
  • for me, this works perfectly! it kees a half-transparent background and makes the dialog canceable outside the dialog content. not exactly what the question was, but for me... perfectly find :) thanks! :) – dy_ Apr 07 '14 at 22:35
1

For API 11+

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Holo_Light_Panel);
kirilv
  • 1,373
  • 1
  • 18
  • 24
0

The simplest way of doing this is that in your DialogFragment's onCreate() method, call

setStyle(DialogFragment.STYLE_NO_FRAME, 0);

And if the view you returned in onCreateView does not have a background specified, the dialog's background will be just transparent.

Why? DialogFragment.STYLE_NO_FRAME means that OS will not do any drawing in the window of the dialog, and your view is 100% responsible for drawing everything about the dialog.

Ian Wong
  • 1,617
  • 14
  • 11
0

The accepted answer causes issue with devices that have a notch, as the statusbar completely disappears and shows an ugly white background.

Instead, the right way for this is to define your own style.

<style name="FullScreenDialogTheme" parent="Theme.MaterialComponents.Dialog">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:statusBarColor">@color/colorPrimary</item>
</style>

Now, this will make the window not have borders and be transparent over the screen.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91