Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android image button

How can i create a button with no text and an image centered horizontally ? I don't want to use an ImageButton because I want to define a different backgound image

like image 605
Arutha Avatar asked Feb 17 '10 18:02

Arutha


People also ask

What is an 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.

What is an image button?

In Android, ImageButton is used to display a normal button with a custom image in a button. In simple words we can say, ImageButton is a button with an image that can be pressed or clicked by the users.

How do I make a clickable image button?

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

Can you make an image a button in Android Studio?

In android, we can add an image to the button by using <ImageButton> attribute android:src in XML layout file or by using the setImageResource() method. In android, we can create ImageButton control in two ways either in the XML layout file or create it in the Activity file programmatically.


2 Answers

You just use an ImageButton and make the background whatever you want and set the icon as the src.

<ImageButton     android:id="@+id/ImageButton01"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@drawable/album_icon"     android:background="@drawable/round_button" /> 

enter image description here

like image 91
CaseyB Avatar answered Oct 14 '22 03:10

CaseyB


just use a Button with android:drawableRight properties like this:

<Button android:id="@+id/btnNovaCompra" android:layout_width="wrap_content"         android:text="@string/btn_novaCompra"         android:gravity="center"         android:drawableRight="@drawable/shoppingcart"         android:layout_height="wrap_content"/> 
like image 27
user2347796 Avatar answered Oct 14 '22 04:10

user2347796