How can I add an image to a button, rather than text?
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.
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.
Placing the <img> tag inside the <button> tag creates a clickable HTML button with an image embedded in it.
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.
Rather humorously, considering your tags, just use the ImageButton
widget.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With