views:

73

answers:

2

alt text

The image above is the first page of my game. Normally the big blue 'button' background image should not show up there.

I declare my custom background image for my buttons in layout file like this:

<Button android:id="@+id/id_button_startgame"
                             android:layout_width="wrap_content"
                             android:layout_height="48dp"
                             android:layout_weight="1"
                             android:textSize="26sp"
                             android:text="@string/start_game"
                             android:textColor="@color/solid_red"
                             android:background="@drawable/button_bg"

                             />

And here's button_bg.xml in drawable folder

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button01_focused" /> 
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/button01_pressed" /> 
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/button01_pressed" /> 
    <item android:drawable="@drawable/button01_idle" /> 
</selector>

As you can see the attached image. The three button below is the normal case. I use them everywhere in my apps. But sometimes the one on the center of the screen shows up. This big button cannot be pressed or anything. It's just up there hovering over my game. I can start the game but obviously can't see the content because this big blue thing cover it all.

I can reproduce this bug by keep launching/exiting my game several times.

I'd love to include more info. But don't know what info should I be giving you. I use FrameLayout to lay the UI above a SurfaceView.

And most of the time this bug DON'T happen. It seems to happen randomly after I launch/exit my game and repeat for several times.

Anyone have seen something like this before? If so please let me know how did you manage to fix it?

A: 

Hi.

Problem solved. Thank you everyone.

Solution: "Don't use transparent background on the layout"

Your answers combined helped me solve this.

Ok, first. I found a way to 100% reproduce the bug.

I have another activity, a 'Pause Game' activity which has translucent background and will hover over everything when launched.

To reproduce the bug: 1. Launch the 'Pause' activity. 2. Slide open the keyboard. 3. This bug will appear behind the 'Pause' activity.

@Orsol - Yes I use transparent background for the layout that contains these buttons

<LinearLayout android:id="@+id/bottom_ui_container"
                android:orientation="vertical"
                android:background="@drawable/transparent_background"
                android:gravity="bottom"
                 android:layout_width="match_parent"
                android:layout_height="match_parent">

                    <LinearLayout android:id="@+id/title_button_container"
                        android:orientation="horizontal"
                         android:background="@drawable/transparent_background"
                        android:gravity="center"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:visibility="gone">

This 2 layout is to have the 3 buttons align horizontally at the bottom like in SS. Still don't understand why my 'button background' become the layout's background after I slide open the keyboard...

@mbanzon and Cristian - Thanks for your tips! =) I'd love to play with hierarchyviewer next time I have problems! BTW.I took this shots using camera because back then I don't know when/how to reproduce the bug.

@Octavian Damiean and CaseyB - Thanks for your help! =) I won't post my layout now since it's solved.

Thank you again everyone! Without you I'd never fix this!

Kakyoin
A: 

I had the same issue. In my case screen background was set to

 <color name="transparent">#00000000</color>

issue was solved by replacing it to

<color name="transparent">@android:color/transparent</color>
Orsol