无法使自定义 DialogFragment 对 Fragment 透明 [英] Can't make the custom DialogFragment transparent over the Fragment

查看:40
本文介绍了无法使自定义 DialogFragment 对 Fragment 透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个片段上创建一个对话框(占据整个屏幕).该对话框需要是一个浮动对话框,它将定位在片段上方,片段在片段外部变暗..

I need to create a dialog over a fragment (that takes up the whole screen). The dialog needs to be a floating dialog that will be positioned over the fragment with the fragment darkened out outside of the fragment..

对于自定义对话框,我有一个带有弯曲边缘的线性布局,无论我做什么,对话框的所有边都有一个黑色边框(非常小).我已经尝试了一切使其透明并消失(这样所有的对话框都只是线性布局 - 曲线框)

For the custom Dialog, i have a linearLayout that has curved edges, no matter what i do, the dialog has a black bordering on all sides (very small). I've tried everything to make it transparent and go away (so that all of the dialog is just the linear layout - curved box)

对于 DialogFragment,这就是我对 onCreateView 所拥有的

For the DialogFragment, this is what I have for onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    LinearLayout layout =(LinearLayout)inflater.inflate(R.layout.custom_dialog, null);
    LinearLayout item = (LinearLayout)layout.findViewById(R.id.display_item);
    populateItemData(item, inflater);
    return layout;
}

custom_dialog 只是一个 LinearLayout,将 android:backgroung 设置为 #000000

custom_dialog is just a LinearLayout that has android:backgroung set to #000000

这是我自定义 Dialog 的风格

This is my style for the custom Dialog

<style name="CustomDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:alwaysDrawnWithCache">false</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

我尝试了这种风格的各种组合(根据我在网上看到的),但我无法摆脱那个烦人的黑色边框,如果我将 LinearLayout 背景设置为除了#000000...

I tried all kinds of combinations in this style (from what I've seen online) and I can't get rid of that annoying black bordering, I can paint it white or any other color if i set that LinearLayout background to anything other than #000000...

我已经在这上面花了 3-4 个小时,我希望其他人可以提供帮助...

I've spent literally 3-4 hours on this, i hope someone else can help out...

推荐答案

尝试

getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

在你的 DialogFragmentonCreateView

这篇关于无法使自定义 DialogFragment 对 Fragment 透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆