How do I remove the black background from a dialog box in Android. The pic shows the problem.
Set these style code in 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 simply change false to true below line
<item name="android:backgroundDimEnabled">true</item>
It will dim your background.
Add this code
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Or this one instead:
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Somehow Zacharias solution didn't work for me so I have used the below theme to resolve this issue...
<style name="DialogCustomTheme" parent="android:Theme.Holo.Dialog.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>
One can set this theme to dialog as below
final Dialog dialog = new Dialog(this, R.style.DialogCustomTheme);
Enjoy!!
This is what I did to achieve translucency with AlertDialog.
Created a custom style:
<style name="TranslucentDialog" parent="@android:style/Theme.DeviceDefault.Dialog.Alert">
<item name="android:colorBackground">#32FFFFFF</item>
</style>
And then create the dialog with:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.TranslucentDialog);
AlertDialog dialog = builder.create();
Same solution as zGnep but using xml:
android:background="@null"
In case you extended the DialogFrament
class, you can set the theme with:
setStyle(DialogFragment.STYLE_NORMAL, R.style.customDialogTheme);
And then make the custom theme in your styles.xml file (see @LongLv's answer for parameters)
Don't forget to add <item name="android:windowCloseOnTouchOutside">true</item>
if you want the dialog to close if the user touches outside the dialog.