问题
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);
回答1:
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.
回答2:
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;
回答3:
This is what worked for me:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
回答4:
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;
来源:https://stackoverflow.com/questions/11717052/android-dialog-fragment-eliminate-black-borders-top-bottom