自定义对话框背景非常奇怪

时间:2012-01-14 14:11:10

标签: android dialog background-color customdialog

我正在为Android创建一款小游戏。目前我只是为菜单屏幕创建UI。

当我做木制主题时,我还想使用自定义对话框来显示高分等,所以它遵循主题。

我找到了一些很好的指南,但是我对这个对话框的背景有一个非常奇怪的问题。对话框几乎是透明的。

我做了什么: - 创建了一个dialog_theme.xml,其中包含:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Dialog" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>
  • 使用我需要的元素创建custom_dialog.xml(标题和内容的TextView以及要关闭的按钮)
  • 创建了一个扩展Dialog的CustomDialog类,让我可以使用我想要的内容和标题轻松构建这些自定义对话框
  • 使用活动中的CustomDialog创建对话框

(我用于此博客的主要指南.androgames.net/10/custom-android-dialog/)

问题是透明背景并不总是透明的(在背景中显示活动ui)。我在这个菜单中有4个自定义按钮。问题是,不是仅显示对话框透明并在背景中显示整个ui,而是拉伸按钮的一个图像并填充整个对话框背景。如果我只使用这个按钮的标准背景,那么对话框背景是透明的,并在背景中显示活动ui。

由于我可能不善于解释,我会展示我的意思: - 导致问题的按钮代码:

<Button
        android:id="@+id/id_about_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/id_achievements_button"
        android:layout_marginTop="15dp"
        android:background="@drawable/selector_about" />

给出了这个结果:(抱歉,我还不能直接在帖子中使用图片) http://dl.dropbox.com/u/2980431/wrong.png

将按钮代码修改为:

<Button
        android:id="@+id/id_about_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/id_achievements_button"
        android:layout_marginTop="15dp"/>

给出这个结果: http://dl.dropbox.com/u/2980431/correct.png

希望有人知道为什么会这样,以及解决问题的方法 - 老实说我完全迷失了。

1 个答案:

答案 0 :(得分:0)

仍然不确定发生了什么。在另一个项目中我遇到了同样的事情 - 自定义半透明对话框背景,另外一个drawable添加到后台。重命名在后台显示错误的drawable,然后清理项目为我修复了这个。

奇怪。