Question

There is a default rectangular background in my Image Button. I want to remove this

This is related codes:

<ImageButton
     android:layout_width="62dp"
     android:layout_weight="1"
     android:layout_height="60dp"
     android:id="@+id/im16"
     android:layout_gravity="fill_horizontal"
     android:src="@drawable/off1"/>
Was it helpful?

Solution

Just try this

<ImageButton
   android:layout_width="62dp"
   android:layout_weight="1"
   android:layout_height="60dp"
   android:id="@+id/im16"
   android:layout_gravity="fill_horizontal"
   android:background="@drawable/off1"/>

just change your android:src to android:background

OTHER TIPS

You will want to set the background of the imageButton to be something invisible. I do this by making the following XML drawable and setting it to the ImageButton's background. This will let the button still show a color when it is clicked, but blank otherwise.

blank_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">     
    <item android:state_pressed="true" android:drawable="@color/some_color" />
    <item android:drawable="@android:color/transparent" />
</selector>


<ImageButton
    android:layout_width="62dp"
    android:layout_weight="1"
    android:layout_height="60dp"
    android:id="@+id/im16"
    android:layout_gravity="fill_horizontal"
    android:src="@drawable/off1"
    android:background="@drawable/blank_selector" />

best solution is

android:background="@null"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top