开发者

Is it possible to have a Button with a background image with text on top?

开发者 https://www.devze.com 2022-12-20 03:57 出处:网络
I need button that has a replicated background pattern and normal button text on top - how to specify this 开发者_Python百科in layout XML?Override android:background on the Button in question.Or, for

I need button that has a replicated background pattern and normal button text on top - how to specify this 开发者_Python百科in layout XML?


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" />.


Consider using ImageButton instead of using regular one.

0

精彩评论

暂无评论...
验证码 换一张
取 消