Inflating a view into Button?
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.
精彩评论