Dialog layout double layered wrong transparant background

我的未来我决定 提交于 2019-12-11 02:16:50

问题


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:

<?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>

//and colors.xml

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

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...


回答1:


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>



来源:https://stackoverflow.com/questions/13362396/dialog-layout-double-layered-wrong-transparant-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!