Android Dialog fragment eliminate black borders (top & bottom)

独自空忆成欢 提交于 2019-12-05 20:56:36

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.

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;

This is what worked for me:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!