this should be an easy one and I really thought that what I was doing was correct but apparently it isn't. I have an image that I want to use as a button, I have the button created and working. But now I just want this image to show up instead of the standatd android "button".
Anyone know how to do this?
Use ImageButton class.
You need to write the
android:background="@drawable/my_pic"
to your xml file at the button. Where my_pic is your pic's name. Hope it helps you.You can Use ImageButtons instead of regular buttons
The just set your background from your image in your XML
A nice tutorial is Here
Follow me, You can use many controls in android to solve this problem (Button, ImageView, ImageButton, or even TextView ... ). Just sets an image as its background and then implements OnClickListener to handle click event.
Example, with ImageView, - in layout file:
in behind-code file:
Make a use of
<selector
Create in your
drawable-hdpi
folder xml file calledbutton_image.xml
and add the following lines:
and then in your main xml where you declare your button add this line
And then you get effect of reall button. Note that you need two pictures to get effect of button being clicked.
If you dont want to use the selector and use just picture instead then just