我有一个习惯AlertDialog
风格使得AlertDialog
盒子透明。它工作正常,除了当我将所需的透明布局膨胀到警报对话框窗口时,它显示为黑色背景。我的目标是拥有一个完全透明的AlertDialog
看起来好像只有 4 个按钮浮动,而不是一个框架。
图一是自定义对话框给我的,图二是我想要的或我的目标。
这是自定义的代码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);
AlertDialog a = imageDialog.create();
a.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
a.setView(view, 0, 0, 0, 0);
a.show();
Edit*
选项卡布局 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>
`
通过测试来查看问题的根源,我发现布局确实是透明的,因为当我更改布局的背景颜色时,警报对话框也会更改。然而,当布局设置为透明时,膨胀布局后面的内容似乎是黑色的。因此,我不确定该做什么,或者这是否是AlertDialog
设置或我的布局代码。