透明AlertDialog具有黑色背景

我有一个自定义AlertDialog风格,使AlertDialog框透明。 它工作正常,除了当我膨胀到期望的透明布局到警报对话窗口,它显示了一个黑色的背景。 我的目标是有一个完全透明的AlertDialog ,好像只有4个button是浮动的,而不是一个框架。 图像一是自定义对话框给我的,图像二是我想要的或者我想要的。

这是自定义Dialog的代码

 <style name="CustomDialog" parent="android:Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowTitleStyle">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:background">@android:color/transparent</item> </style> 

这是我在我的onCreate()

 AlertDialog.Builder imageDialog = new AlertDialog.Builder(TimeLine.this, R.style.CustomDialog); inflater = getLayoutInflater(); View view=inflater.inflate(R.layout.tabs, null);![enter image description here][1] AlertDialog a = imageDialog.create(); a.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); a.setView(view, 0, 0, 0, 0); a.show(); 

当前警报对话框

所需的AlertDialog

*编辑**** **标签布局xml的代码在这里 `

 <RelativeLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/tabLayout" android:background="#000000ff"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button2" android:layout_marginTop="206dp" android:layout_below="@+id/button4" android:layout_alignStart="@+id/button4" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button3" android:layout_alignTop="@+id/button2" android:layout_alignParentStart="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button4" android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_marginTop="100dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:layout_marginTop="100dp" /> </RelativeLayout> 

`

从testing看问题的根源是什么,我发现布局是透明的,因为当我改变布局的背景颜色时,警告对话框也改变了。 但是,当布局设置为透明时,似乎膨胀的布局背后是黑色的。 因此,我不确定要做什么,或者它是AlertDialog设置还是我的布局代码。

问题是AlertDialog builder实际上不适合devise透明对话框,并且总是会有这个黑色的背景,而实际上它是一个主题,而是使用Dialog来创build一个透明的主题。

样品:

 Dialog alertDialog = new Dialog(this); alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); alertDialog.setContentView(R.layout.tabs); alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); alertDialog.show(); 

使用Dialog不需要任何主题操作的透明背景,所以它基本上很容易。

你有没有尝试过使用这样的东西:

 <style name="CustomDialog" parent="@android:style/Theme.Translucent"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:colorBackgroundCacheHint">@null</item> ... </style> 

编辑

在java代码中试试这个

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

在你的R.layout.tabs

更换

 <RelativeLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/tabLayout" android:background="#000000ff"> 

 <RelativeLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/tabLayout" android:background="@android:color/transparent">