Cannot make custom DialogFragment dialog transparent over fragment

I need to create a dialog over a fragment (which occupies the entire screen). The dialog should be a floating dialog, which will be located above the fragment with the fragment darkened outside the fragment.

For a user dialog, I have a linearLayout with curved edges, no matter what I do, the dialog has black bordering on all sides (very small). I tried everything to make it transparent and go away (so the whole dialog box is just a linear layout - a curved block)

For 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 an android: backgroung is set to # 000000

This is my style for user dialogue.

 <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 saw on the Internet), and I can’t get rid of this annoying black border, I can draw it white or any other color if I set this LinearLayout background to anything but # 000000 ...

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

+58
android android-layout android-fragments android-dialogfragment android-dialog
Nov 08 '11 at 3:20
source share
7 answers

Try

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

in DialogFragment onCreateView

+196
Feb 16 2018-12-16T00:
source share

Try ( How to create a 100% DialogFragment user dialog ) this work for dialogue

  Dialog dialog = new Dialog(getActivity()); dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // layout to display dialog.setContentView(R.layout.add_edit); // set color transpartent dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); 
+19
Feb 12 '13 at 10:37
source share

In onActivityCreated

 getDialog().getWindow().getAttributes().alpha = 0.9f; // An alpha value to apply to this entire window. An alpha of 1.0 means fully opaque and 0.0 means fully transparent 

for DialogFragment transparent

+6
Nov 27 '14 at 7:01
source share

For completely transparent use: setStyle (DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

For a custom background, create a style file in the values ​​folder (values ​​/style.xml) and use it: setStyle (DialogFragment.STYLE_NO_FRAME, yourpackagename.R.style.YOURE_CUSTOM_STYLE);

in your style file override attribute: android: windowBackground will be @ color / DialogBackgroundBlackSemiTransparent

+5
Jun 15 '15 at 13:25
source share

Ask your topic how it worked for me

 <style name="MyDialog" parent="Base.Theme.AppCompat.Light.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> </style> 

And in your dialog dialog like this

 public class Progress extends DialogFragment { int style = DialogFragment.STYLE_NO_TITLE; int theme = R.style.MyDialog; public Progress() { } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(style, theme); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.progress, container, false); } } 
+5
Mar 01 '16 at 5:41
source share

Those who use the AlertDialog builder in onCreateDialog instead of onCreateView can assign a theme, such as the following code. A complete set of topics can be found from R.style . Do not forget that some of them were supported recently and are not available on older device phones.

 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Translucent); View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_album, null); builder.setView(view); return builder.create(); } 
+3
Oct. 16 '13 at 6:37
source share

Try it if you want:

 public TransparentDialog() { super(); setStyle(STYLE_NO_FRAME, R.style.AppTheme); } 
+1
Dec 28 '12 at 20:16
source share



All Articles