【问题标题】:Dialog layout double layered wrong transparant background对话框布局双层错透明背景
【发布时间】:2012-11-01 23:30:27
【问题描述】:

我想制作一个白色的、无边框的弹出视图。为此,我使用了一个自定义样式的自定义对话框:

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>

//和colors.xml

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

但是,正如您在图像中看到的那样,弹出窗口有一些错误......它似乎是双层的,第一层仍然有边框,透明背景仍然是黑色......我想我正在处理有问题,但我没看到...

【问题讨论】:

    标签: android dialog styles themes


    【解决方案1】:

    使用 Translucent Theme 并使用 android 自己的透明颜色。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2023-03-02
      • 2012-06-03
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多