2

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);
Jose_GD
  • 2,279
  • 1
  • 21
  • 34
pulancheck1988
  • 2,024
  • 3
  • 28
  • 46
  • ahh Android, every view has its own little hidden puzzles to spend hours on sovling... so fun you are. I hope there's more undocumented, random fun in 5.0 ! – samus Dec 03 '12 at 20:28

4 Answers4

3

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.

digiphd
  • 2,319
  • 3
  • 23
  • 22
3

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;
pulancheck1988
  • 2,024
  • 3
  • 28
  • 46
  • Oh your version of Android isn't quite as random as mine, so unfortunately this random solution to a random problem didn't work for me. Luckily enough hideous black bars are in style these days. – samus Dec 03 '12 at 20:43
3

This is what worked for me:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Leo Landau
  • 1,785
  • 17
  • 25
1

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;
dineth
  • 9,822
  • 6
  • 32
  • 39