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

梦想与她 提交于 2019-12-24 18:37:18

问题


I need button that has a replicated background pattern and normal button text on top - how to specify this in layout XML?


回答1:


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




回答2:


Consider using ImageButton instead of using regular one.



来源:https://stackoverflow.com/questions/2276438/is-it-possible-to-have-a-button-with-a-background-image-with-text-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!