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?
The image buttons in the HTML document can be created by using the type attribute of an <input> element. Image buttons also perform the same function as submit buttons, but the only difference between them is that you can keep the image of your choice as a button.
Complete HTML/CSS Course 2022 To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image.
Make a use of <selector
Create in your drawable-hdpi
folder xml file called button_image.xml
and add the following lines:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/picture" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/picture_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/picture_pressed" />
<item android:drawable="@drawable/picture" />
</selector>
and then in your main xml where you declare your button add this line
android:background="@drawable/button_image"
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
android:background="@drawable/myimage"
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