gabor.orosz
gabor.orosz

Reputation: 443

DialogFragment remove transparent black

I need to create a DialogFragment without the transparent black layer in the background, or at least swap it with a transparent white one.

Tried to use this trick from a different SO answer, but it's not what I looking for: getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.RED));

As you can see on this image, there is a red area around the dialog, but it's not the one I looking for, there must be an other background: https://www.dropbox.com/s/4hlgil6btxtqcg4/dialog.png

If you have any idea, or workaround, please share with me.

Thank you!

Upvotes: 3

Views: 5120

Answers (2)

Dyna
Dyna

Reputation: 2305

You can set it to the color transparent:

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Or create your own custom layout to your dialog, here it is an example.

Upvotes: 4

Hardik
Hardik

Reputation: 17441

you have to set android:windowIsFloating to false and android:windowBackground to your custom color in the dialog style:

styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="MyDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowBackground">@color/orange_transparent</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowTitleStyle">@null</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:gravity">center</item>
    </style>

</resources>

TestDialogFragment

public class TestDialogFragment extends DialogFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialog);
    }
}

Upvotes: 11

Related Questions