nasaa
nasaa

Reputation: 2731

android dialog transparent

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

Upvotes: 31

Views: 45613

Answers (7)

Sri Harsha Chilakapati
Sri Harsha Chilakapati

Reputation: 11950

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.

Upvotes: 0

Ian Wong
Ian Wong

Reputation: 1687

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.

Upvotes: 0

kirilv
kirilv

Reputation: 1431

For API 11+

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Holo_Light_Panel);

Upvotes: 1

duggu
duggu

Reputation: 38439

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();

Upvotes: 10

ashish
ashish

Reputation: 878

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.

Upvotes: 20

Zsolt Safrany
Zsolt Safrany

Reputation: 13620

try this:

mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

Upvotes: 63

ingsaurabh
ingsaurabh

Reputation: 15267

Try below code

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

Upvotes: 97

Related Questions