pulancheck1988
pulancheck1988

Reputation: 2064

Android Dialog fragment eliminate black borders (top & bottom)

Need to eliminate top and bottom borders from a dialog fragment. How do you do it?

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setCancelable(true);

    LayoutInflater inflater = LayoutInflater.from(activity);
    View view = inflater.inflate(R.layout.variants_dialog, null);

    // setup views
    setupListView(view);
    ...

    builder.setView(view);
    return builder.create(); // HERE I HAVE TOP & BOTTOM BLACK BORDERS

This doesnt do nothing:

        builder.setView(view);
        AlertDialog result = builder.create();
        result.getWindow().setBackgroundDrawable(new ColorDrawable());
        return result;

There is no such method:

         dialog.setView(layout, 0, 0, 0, 0);

Upvotes: 2

Views: 6659

Answers (4)

Leo Landau
Leo Landau

Reputation: 1795

This is what worked for me:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

Upvotes: 3

pulancheck1988
pulancheck1988

Reputation: 2064

FOUND SOLUTION!!

There is no

setView(layout, 0, 0, 0, 0);

on builder from dialogFragment, but AlertDialog has this method.. so instead of returning

builder.create();

do this

//dont set view for builder!
AlertDialog result = builder.create();
result.setView(view, 0, 0, 0, 0);
return result;

Upvotes: 3

dineth
dineth

Reputation: 9942

I had a similar problem not too long ago. The problem is that the the Builder doesn't let you play with the padding of the dialog at all. My work around was to create a subclass of the AlertDialog:

final class PaddinglessDialog extends AlertDialog {
    public PaddinglessDialog(Context context, int theme) {
        super(context, theme);
    }
}

Then i went on to use it like this:

PaddinglessDialog alertDialog = new PaddinglessDialog(this, android.R.style.Theme_Holo_Light_Panel);
View layout = LayoutInflater.from(this).inflate(R.layout.my_dialog_layout, ...);
alertDialog.setView(layout, 0, 0, 0, 0);
alertDialog.setCanceledOnTouchOutside(false);
...
dialog = alertDialog;

Upvotes: 1

digiphd
digiphd

Reputation: 2339

I am not that familiar with DialogFragments, however, with regular dialogs to do this you would usually R.value.styles and add:

 <style name="myDialog" parent="@android:style/Theme.Dialog">
    <item name="android:buttonStyle">@style/Button</item>
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:textColor">#FFFFFFFF</item>
    <item name="android:shadowColor">#cdc9c9</item>
    <item name="android:shadowDx">0</item>
    <item name="android:shadowDy">-1</item>
    <item name="android:shadowRadius">0.5</item>
</style>

And set your dialog to have the stile myDialog. However, with dialogFragments, it seems you need to define the style when you initialise it, DialogFragment.STYLE_NO_FRAME;, Hope that helps somewhat, although I know it wasn't a complete answer.

Upvotes: 3

Related Questions