开发者

Inflating a view into Button?

开发者 https://www.devze.com 2023-01-05 09:38 出处:网络
I saw this questions unanswered on some forums and wonder if anyone have a clue on how to answer. Let\'s say for instance a button is needed with a picture and a text. It would seem natural to create

I saw this questions unanswered on some forums and wonder if anyone have a clue on how to answer.

Let's say for instance a button is needed with a picture and a text. It would seem natural to create an xml view and then inflate it into the Button. Is this possible?

At the moment I don't need the button to look clickable or change it's color at click, but it could also be interesting to consider how this will be affected by making the inflate.

Btw, I found this one tutorial describing a solution to the same problem, but they were writing a class extending View to obtain the goal. That seems a bit overklill to me. http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-usin开发者_如何学编程g-a-custom-view/

Thanks in advance! Anna


Make a XML layout of your custom Button, that contains the TextView and ImageView. Put the following attributes to the root layout in the file:

android:background="@android:drawable/btn_default"
android:focusable="true"
android:clickable="true"

and you'll get what you need.

0

精彩评论

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