Can't make the custom DialogFragment transparent over the Fragment

Tolga E picture Tolga E · Nov 8, 2011 · Viewed 55.1k times · Source

I need to create a dialog over a fragment (that takes up the whole screen). The dialog needs to be a floating dialog that will be positioned over the fragment with the fragment darkened out outside of the fragment..

For the custom Dialog, i have a linearLayout that has curved edges, no matter what i do, the dialog has a black bordering on all sides (very small). I've tried everything to make it transparent and go away (so that all of the dialog is just the linear layout - curved box)

For the DialogFragment, this is what I have for onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    LinearLayout layout =(LinearLayout)inflater.inflate(R.layout.custom_dialog, null);
    LinearLayout item = (LinearLayout)layout.findViewById(R.id.display_item);
    populateItemData(item, inflater);
    return layout;
}

custom_dialog is just a LinearLayout that has android:backgroung set to #000000

This is my style for the custom Dialog

<style name="CustomDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:alwaysDrawnWithCache">false</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

I tried all kinds of combinations in this style (from what I've seen online) and I can't get rid of that annoying black bordering, I can paint it white or any other color if i set that LinearLayout background to anything other than #000000...

I've spent literally 3-4 hours on this, i hope someone else can help out...

Answer

C.d. picture C.d. · Feb 16, 2012

Try

getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

in your DialogFragment's onCreateView