By Alvin Alexander. Last updated: June 6, 2016
To set an image on an Android ImageButton
, you basically just need to put your image in the “res/drawable” directories, and then add this tag to your ImageButton
XML definition:
android:src="@drawable/my_image"
That assumes the image file is named my_image.png.
Here’s a full ImageButton
example to demonstrate this:
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/landingPagePinButton" android:layout_centerHorizontal="true" android:layout_gravity="center" android:src="@drawable/my_image" android:clickable="true" android:minHeight="36dp" android:minWidth="36dp" android:background="@android:color/darker_gray"/>
There is even more you can do with images on ImageButton’s. See the Android ImageButton docs for more information.