对话框宽度

时间:2018-07-04 12:04:07

标签: android dialogfragment

我正在使用dialogFragment制作自己的自定义片段,但其大小看起来不像priview中的
这就是预览中显示的内容

enter image description here

这就是显示对话框时发生的情况

enter image description here

我希望它看起来完全像我的预览-我该怎么办?

1 个答案:

答案 0 :(得分:1)

尝试一下

    final Dialog dialog = new Dialog(mContext, R.style.Theme_Transparent);

    View view = LayoutInflater.from(mContext)
                           .inflate(R.layout.layout_custom_dialog, null);
    dialog.setContentView(view);

    Window window = dialog.getWindow();
    WindowManager.LayoutParams wlp = window.getAttributes();
    wlp.width = wlp.MATCH_PARENT;
    wlp.gravity = Gravity.TOP;
    wlp.flags &= ~WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
    window.setAttributes(wlp);

并将其添加到styles.xml文件

    <style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>