Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add image for button in android?

How can I add an image to a button, rather than text?

like image 440
Adham Avatar asked Nov 17 '10 21:11

Adham


People also ask

How will you add graphics to button?

Copy your image file within the Res/drawable/ directory of your project. While in XML simply go into the graphic representation (for simplicity) of your XML file and click on your ImageButton widget that you added, go to its properties sheet and click on the [...] in the src: field. Simply navigate to your image file.

Can we use image as a button in Android Studio?

The image on the surface of the button is defined either by the android:src attribute in the <ImageButton> XML element or by the ImageView. setImageResource(int) method. To remove the standard button background image, define your own background image or set the background color to be transparent.

How do I make an image a button?

Placing the <img> tag inside the <button> tag creates a clickable HTML button with an image embedded in it.

How do you make an image clickable on android?

To make a View clickable so that users can tap (or click) it, add the android:onClick attribute in the XML layout and specify the click handler. For example, you can make an ImageView act like a simple Button by adding android:onClick to the ImageView . In this task you make the images in your layout clickable.


2 Answers

Rather humorously, considering your tags, just use the ImageButton widget.

like image 156
Kevin Coppock Avatar answered Oct 06 '22 05:10

Kevin Coppock


Simply use ImageButton View and set image for it:`

 <ImageButton     android:id="@+id/searchImageButton"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignParentTop="true"     android:layout_alignParentRight="true"     android:src="@android:drawable/ic_menu_search" /> 
like image 43
Bhagwat K Avatar answered Oct 06 '22 05:10

Bhagwat K