【问题标题】:dialogframgent width对话片段宽度
【发布时间】:2018-07-04 12:04:07
【问题描述】:

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

当显示对话框时会发生这种情况

我希望它看起来与我的预览完全一样 - 我应该怎么做?

【问题讨论】:

    标签: android dialogfragment


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 2011-02-07
      • 2014-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多