android - 对话框 fragment 宽度

标签 android dialogfragment

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

enter image description here

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

enter image description here

我希望它看起来和我的预览一模一样 - 我应该怎么做?

最佳答案

试试这个

    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>

关于android - 对话框 fragment 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51173277/

相关文章:

android - Jetpack Compose 自定义 UI - 带动画的速度计

android - alertdialog 正/负按钮与全屏对话框 fragment 中的父级不匹配

android - DialogFragment 监听器

java - 防止 DialogFragment 将应用程序发送到节能模式

android - 如何在 Android 上使用 Kotlin 显示 Toast?

android - 如何将房间数据库导出为 .CSV

android - 光标窗口 : window is full

android - onActivityResult应该在哪里处理,dialog fragment,fragment,还是activity?

android - DialogFragment + listview = getView 调用次数过多

android - 在 ImageView 中设置 Vector Drawable 导致应用程序在旧 SDK 中崩溃