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"/>

1

7 Answers 7

97

Try below code

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
5
  • Now a new problem has comeup. the entire screen flickers as described here - stackoverflow.com/questions/3379322/… I was wondering if there is any workaround or if i can get the same effect without using the dialog?
    – nasaa
    May 20, 2011 at 8: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, 2011 at 9:10
  • I dont know if that works or will create the same problem try using Activity instead Dialog
    – ingsaurabh
    May 20, 2011 at 9:13
  • Turn the animation of activity off and set the theme transparent in xml it will work as Dialog
    – ingsaurabh
    May 20, 2011 at 9: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 6, 2012 at 16:12
63

try this:

mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
3
  • 4
    is there anyway to change a dialog to 50% opacity without changing its background?
    – Green_qaue
    Sep 29, 2012 at 16:31
  • The only problem about this solution is that it will not dismiss the title line on android 4+
    – Pozzo Apps
    Jun 21, 2013 at 17:52
  • 2
    you need to call mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE) to hide the title bar. Nov 8, 2013 at 13:44
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.

1
  • 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, 2014 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();
1
  • 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 7, 2014 at 22:35
1

For API 11+

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Holo_Light_Panel);
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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.