透明AlertDialog有黑色的背景

透明AlertDialog有黑色的背景

本文介绍了透明AlertDialog有黑色的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义alertdialog风格,使alertdialog框透明。它工作正常,只是,当我吹我想要的透明布局到警报对话框窗口,它显示了一个黑色的背景。我的目标是有一个完全透明alertdialog到它好像只有4个按键的浮动而不是框架。图像中的一个是自定义对话框给我,影像二是我的希望或者是我的目标了。这里是code到自定义对话框

I have a custom alertdialog style that makes the alertdialog box transparent. It works fine except that when I inflate my desired transparent layout into the alert dialog window, it shows up with a black background. My goal is to have a completely transparent alertdialog to where it seems as if there are only 4 buttons floating rather than a frame.Image one is what the custom dialog is giving me, image two is my desired or what I am aiming for. Here is the code to the custom 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()

Here is what I am calling in my 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();

***编辑****在code为标签的布局XML是在这里    `

***Edit****The code for the tabs layout xml is here `

<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设置或我的布局code。

From testing to see what the source of the problem is, I have found out that it is true that the layout is transparent because when I change the background color of the layout, so does the alert dialog change. However when the layout is set to transparent, it seems that what is behind the inflated layout is black. And because of that I am unsure of what to do or whether it is the alertdialog settings or my layout code.

推荐答案

问题是, AlertDialog建设者其实是不好的设计透明的对话,并始终有这样的黑色背景,其实是一个主题的话,而不是使用对话框以创建一个透明的主题吧。

The problem is that AlertDialog builder is actually not good for designing transparent dialog and will and always have this black background which is actually a Theme for it, instead use the Dialog to create a transparent theme instead.

示例:

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();

使用对话框不需要任何操作的主题为透明背景,因此基本上是容易的。

Using Dialog does not require any theme manipulation for transparent background so it is basically easy.

这篇关于透明AlertDialog有黑色的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:43