Search code examples
androiddialogbackground-colorcustomdialog

Custom dialog background is acting very strange


I am creating a small game for Android. At the moment I'm just creating the UI for the menu screen.

As I'm doing a wooden theme, I also want to use a custom dialog for showing highscores etc so it follows the theme.

I have found some good guides, but I have this very strange problem with the background of the dialog. The dialog is almost transparent.

What I have done: - created a dialog_theme.xml with:

<?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>
  • created custom_dialog.xml with the elements I need (TextView for title and content, and button to close)
  • created a CustomDialog class which extends Dialog, and lets me build these custom dialogs rather easy with the content and title I want
  • using the CustomDialog in the activity to create the dialog

(the main guide I used for this blog.androgames.net/10/custom-android-dialog/ )

The problem is that the transparent background isn't always transparent (showing the activity ui in the background). I have 4 custom buttons in this menu. Problem is that instead of just showing the dialog transparent and showing the whole ui in the background, then one of the images for a button is stretched and fills the whole dialog background. If I just use a standard background for this one button then the dialog background is transparent and shows the activity ui in the background as it should.

As I might have been bad at explaining I will show pictures of what I mean: - Code for the button that causes the problem:

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

Gives this result: (sorry but I can't use pictures directly in the post yet) http://dl.dropbox.com/u/2980431/wrong.png

Modifying the button code to:

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

Gives this result: http://dl.dropbox.com/u/2980431/correct.png

Hope someone got an idea about why this is happening, and a solution to fix it - to be honest I am totally lost.


Solution

  • Still not sure what happened. In another project I came across the same thing - custom semi transparent dialog background, got another drawable added to the background. Renaming the wrong drawable showing in the background, and then clean the project fixed this for me.

    Strange.