Dialog with transparent background in Android Dialog with transparent background in Android android android

Dialog with transparent background in Android


Add this code

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Or this one instead:

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);


<style name="NewDialog">    <item name="android:windowFrame">@null</item>    <item name="android:windowBackground">@android:color/transparent</item>    <item name="android:windowIsFloating">true</item>    <item name="android:windowContentOverlay">@null</item>    <item name="android:windowTitleStyle">@null</item>    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>    <item name="android:backgroundDimEnabled">false</item>    <item name="android:background">@android:color/transparent</item></style>

use in java

Dialog dialog = new Dialog(this, R.style.NewDialog);

I hope help you !


I've faced the simpler problem and the solution i came up with was applying a transparent bachground THEME. Write these lines in your styles

    <item name="android:windowBackground">@drawable/blue_searchbuttonpopupbackground</item></style><style name="Theme.Transparent" parent="android:Theme">    <item name="android:windowIsTranslucent">true</item>    <item name="android:windowBackground">@android:color/transparent</item>    <item name="android:windowContentOverlay">@null</item>    <item name="android:windowNoTitle">true</item>    <item name="android:windowIsFloating">true</item>    <item name="android:backgroundDimEnabled">false</item></style>

And then add

android:theme="@style/Theme.Transparent"

in your main manifest file , inside the block of the dialog activity.

Plus in your dialog activity XML set

 android:background= "#00000000"