I have a DialogFragment which I pass the custom layout for display.

To this layout I set the background in which I round up a bit of the edge. And I expect to see a beautiful layout with rounded edges, but it turns out this

enter image description here

everything seems to be like, but why does this background appear above and below the form?

When I had such a situation with activism (it was the same), I solved it as described here

I added a custom theme, a background as I need and set the theme in the manifest for this activi ...

But in this situation, I can not set a custom theme in the manifest for the layout which I pass to the DialogFragment , since in the manifest only activation ...

I tried to assign the DialogFragment theme itself.

Here is my topic for him, which describes the animation

 <style name="DialogFragmentTheme" parent="@android:style/Theme.Panel"> <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item> </style> <style name="MyAnimation.Window" parent="@android:style/Animation.Activity"> <item name="android:windowEnterAnimation">@anim/open_next</item> <item name="android:windowExitAnimation">@anim/close_next</item> </style> 

and this is how I add to it those parameters that helped me earlier when there was a problem with activating it turns out like this

 <style name="DialogFragmentTheme" parent="@android:style/Theme.Panel"> <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item> <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> <style name="MyAnimation.Window" parent="@android:style/Animation.Activity"> <item name="android:windowEnterAnimation">@anim/open_next</item> <item name="android:windowExitAnimation">@anim/close_next</item> </style> 

But nothing happens ... In activit it works, it is not here ... I think because the layout has already been laid out in the layout and it processes it right away, but here I kind of dynamically transfer the layout I need to display in DialogFragment ...

How to get rid of these pieces over and under the form?

Amendment:

As it became clear, the problem is as follows ... I have an animation on this dialog and I implement it through setting styles when I create the builder

like this

 AlertDialog.Builder adb = new AlertDialog.Builder(getActivity(), R.style.DialogFragmentTheme); 

and then the animation works fine. If you set R.style.DialogFragmentTheme through the onResume() method, or in the XML file or in the getTheme() method, then the animation does not work. But if the animation does not work, then the method

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

and there is no frame around the dialogue. But then the animation does not work ...

How can you make the animation work and the frame around it not to be?

  • Did you break the dialog markup through the android:theme="@style/..." ? - Yuriy SPb
  • @ YuriySPb added a question ... - Aleksey Timoshchenko
  • And if in the topic of the dialogue, in addition to android:windowBackground register and just android:background , is also transparent? - Yuriy SPb
  • @ YuriySPb is not there, nothing changes ... I am now creating the exact same dialogue, only in a new test project ... And I’ll see if it’s the same there or ok ... - Aleksey Timoshchenko

2 answers 2

Try to register in DialogFragment

 @Override public void onResume() { super.onResume(); getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.DialogFragmentTheme); } 
  • It seems like your method works, but only if you remove the animation ... If I connect the animation again when creating the builder AlertDialog.Builder adb = new AlertDialog.Builder (getActivity (), R.style.DialogFragmentTheme) then become as shown in the screenshot .. I added an amendment to the question, there are ideas how you can try to make the animation work and there is no framework? - Aleksey Timoshchenko
  • Is there an option to specify in the animation both the initial and the final state of the object? If yes - just for both states list the absence of the frame. And judging by the type of dialogue - there the shadow is used in the effects. It should be possible to disable it. This is where a similar task is discussed: stackoverflow.com/questions/17045726/… - DimXenon

I suggest using Activity instead of DialogFragment . In the AndroidManifest.xml file, add a new style, with the setting of the transparent background for Activity

  <activity android:name=".activities.DemoActivity" android:screenOrientation="unspecified" android:theme="@style/Theme.AppCompat.Translucent" /> 

Below is the style for the Activity with a transparent background, i.e. you will no longer have a standard DialogFragment .

 <style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar"> <item name="android:background">#00000000</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> </style> 

Add actuality to the screen:

 Intent demoActivity = new Intent(this, DemoActivity.class); startActivity(demoActivity); 
  • Yes, but I use different layout files ... About 7 different ... Using your approach, I’ll have to create an activi for every so-called dialogue ... - Aleksey Timoshchenko