Nazerke
Nazerke

Reputation: 2098

Making background of a button transparent makes it unclickable

I have a button which responds to clicks just fine until i make it transparent. I have zero idea what could go wrong. All the other buttons with transparent background respond to click. Here is the xml and the button in question is id:door_handle:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/wall4EarthRoom"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/door_wall" >

    <Button
        android:id="@+id/hanging_walk"
        android:layout_width="80dp"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="268dp"
        android:layout_marginTop="49dp"
        android:background="@android:color/transparent"
        android:clickable="false"
        android:onClick="goOut" />

    <Button
        android:id="@+id/door_handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="279dp"
        android:layout_marginTop="136dp"
        android:onClick="openTheDoor" 
        android:background="@android:color/transparent"/>

    <Button
        android:id="@+id/peephole_doorwall"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="289dp"
        android:layout_marginTop="127dp"
        android:background="@android:color/transparent"
        android:clickable="false"
        android:onClick="zoomImage" />

    <ImageView
        android:id="@+id/queen_rabbit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

I'll repeat just in case: the button works if i delete the line "android:background="@android:color/transparent""

Upvotes: 0

Views: 497

Answers (3)

what is sleep
what is sleep

Reputation: 905

Try adding some actual height to that button, like 30dp, the button does not have any text so wrap_content might make it too small.

Upvotes: 1

EinsL
EinsL

Reputation: 73

I removed the onClick event of the door_handle button in the xml and created this. And its working for me.

    btn1 = (Button)findViewById(R.id.door_handle);
    btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "door handle", Toast.LENGTH_SHORT).show();

        }
    });

Im using Android 4.3 - API Level 18

What target level are you using?

Upvotes: 0

Freelancer
Freelancer

Reputation: 86

If the above answer doesn't work, and you want a quick fix use a transparent image, instead of a transparent color.

Upvotes: 0

Related Questions