Title says it all: I need button that has a replicated background pattern and normal button text on top - how to specify this in layout XML?
views:
336answers:
2`ImageButton` doesn't allow you to set a text label.
Christopher
2010-02-16 21:46:24
Will ImageButton replicate the background image?
Eno
2010-02-16 21:52:39
@Chris: Thought so...
Eno
2010-02-16 21:52:55
A:
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
2010-02-16 21:44:11
@Chris: I hadn't looked at the styling/theming in Android and that is a good approach to me.
Eno
2010-02-16 22:06:17
@Chris: Im assuming StateListDrawable allows me to swap images based on state? How would I use that for my buttons?
Eno
2010-02-16 22:09:23
See the example here: http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view/2016344#2016344You just declare which image you want to show when the button is focused/pressed/disabled/none-of-the-above etc.
Christopher
2010-02-17 07:16:31