I need button that has a replicated background pattern and normal button text on top - how to specify this in layout XML?
Asked
Active
Viewed 1,874 times
2 Answers
0
Consider using ImageButton instead of using regular one.

Sorantis
- 14,496
- 5
- 31
- 37
-
`ImageButton` doesn't allow you to set a text label. – Christopher Orr Feb 16 '10 at 21:46
-
Will ImageButton replicate the background image? – Eno Feb 16 '10 at 21:52
0
Override android:background
on the Button
in question. Or, for reuse you could declare your own style, overriding android:background
from the base button style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyButtonStyle" parent="Widget.Button">
<item name="android:background">@drawable/fancy_button</item>
</style>
</resources>
In either case, your fancy_button
drawable would be an image, or more likely a StateListDrawable
.
For the Button
instances you wish to apply this to, you'd do:
<Button style="@style/MyButtonStyle" />
.

Christopher Orr
- 110,418
- 27
- 198
- 193
-
@Chris: I hadn't looked at the styling/theming in Android and that is a good approach to me. – Eno Feb 16 '10 at 22:06
-
@Chris: Im assuming StateListDrawable allows me to swap images based on state? How would I use that for my buttons? – Eno Feb 16 '10 at 22:09
-
See the example here: http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view/2016344#2016344 You just declare which image you want to show when the button is focused/pressed/disabled/none-of-the-above etc. – Christopher Orr Feb 17 '10 at 07:16