I need to be able to show a button in my layout, but I want the button to have an image (small Icon) and text inside of it.
something like this:
___________________
/ *** SOME TEXT /
/_**_______________/
where the *s are an image
So what I thought to do is a linear layout with a background and make it clickable - which will probably work, but that means that it won't behave exactly like a button...
Do you have a better idea on how to do that?
Thanks, e.
In your xml layout for the button, add:
<Button
...
android:drawableLeft="@drawable/myIcon"
android:drawablePadding="5dp"
android:paddingLeft="10dp"
android:text="My text" />
Where myIcon.png is your icon in the drawable folder.
EDIT Added padding. EDIT 2: Added padding to left of the icon.
In your XML, you can use ImageButton (which was added in API level 1, so it should be available)
<ImageButton
android:id="@+id/imageBtn"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btnSrc"
/>
This method doesn't require you to add padding to a side.
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