Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image button style in android

Tags:

android

button

Hi am confused with image button options in android. I have created three image buttons with the following xml

<ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/folder_add" />

    <ImageButton
        android:id="@+id/imageButton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageButton1"
        android:layout_toLeftOf="@+id/imageButton1"
        android:src="@drawable/search" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageButton4"
        android:layout_toLeftOf="@+id/imageButton4"
        android:src="@drawable/advancedsettings" 
        style="?android:attr/borderlessButtonStyle" />

But the out is like button with image on its .. Please help me to show the image only as button..Thnx in advance!

like image 726
user1682133 Avatar asked Sep 26 '12 10:09

user1682133


People also ask

What is the use of image button in android?

Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button , with the standard button background that changes color during different button states.

How do I make a clickable image button?

To avoid confusion rename your button android:onClick="onClick" , like android:onClick="imageButtonOnClick" . Thank you!

How do I put text on an image button?

You cannot set text to ImageButton because it has no method as setText() or android:text property. ImageButtons can't have text (or, at least, android:text isn't listed in its attributes). It looks like you need to use Button (and look at drawableTop or setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)) .


2 Answers

Put this tag in your ImageButton

android:background="@null"

This will do it.

like image 193
Tobias Moe Thorstensen Avatar answered Oct 18 '22 00:10

Tobias Moe Thorstensen


You can also use a transparent color: This will solve your problem.

android:background="@android:color/transparent"
like image 27
Chirag Avatar answered Oct 17 '22 23:10

Chirag