本文介绍了对话框布局双层错TRANSPARANT背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个白色的,没有边界,弹出视图。要做到这一点,我使用自定义对话框,自定义样式:

I want to make a white, no bordered, popup view. To accomplish this I use a custom dialog with a custom style:

public Builder createNewDialog(int type) {
        AlertDialog.Builder dlg = null;
        switch (type) {
        case (1):

            dlg = new AlertDialog.Builder(new ContextThemeWrapper(this,
                    R.style.CustomDialogTheme));

            LayoutInflater inflater = this.getLayoutInflater();

            dlg.setView(inflater.inflate(R.layout.dialognewplayer, null))
                    .setPositiveButton("Add Player", null).setNegativeButton("Cancel", null).create();
            break;
        }
        return dlg;
    }

// styles.xml:

//styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="android:Theme.Light"></style>
    <style name="CustomDialogTheme" parent="android:Theme.Dialog">
         <item name="android:windowBackground">@color/transparent_color</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:background">#ffffff</item>
    </style>

</resources>

//和colors.xml

//and colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
       <color name="transparent_color">#ffffff</color>
</resources>

然而,正如你可以在图片看到,在弹出的有一些错误...这似乎是双层与第一层仍然有一个边界,而TRANSPARANT背景仍然是黑色的。我觉得我处理一些错误,但我没有看到它...

However, as you can see at the image, the popup has some errors... it appears to be double layered with the first layer still having a border, and the transparant background is still black.. I think I am handling something wrong but I am not seeing it...

推荐答案

使用半透明的主题,并使用Android自身的透明色。

Use the Translucent Theme and use android own transparent color.


<style name="CustomDialogTheme" parent="@android:style/Theme.Translucent">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@android:color/transparent</item>
</style>

这篇关于对话框布局双层错TRANSPARANT背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 23:25