Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't make the custom DialogFragment transparent over the Fragment

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...

like image 877
Tolga E Avatar asked Nov 08 '11 03:11

Tolga E


People also ask

Is DialogFragment deprecated?

This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle. A fragment that displays a dialog window, floating on top of its activity's window.

How do you dismiss a DialogFragment?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.

What is the difference between dialog & DialogFragment?

Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.

How do you show DialogFragment?

Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.


1 Answers

Try

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

in your DialogFragment's onCreateView

like image 174
C.d. Avatar answered Sep 23 '22 02:09

C.d.