Android add image to button

Posted by Christiaan de Jong on Stack Overflow See other posts from Stack Overflow or by Christiaan de Jong
Published on 2012-09-19T09:34:31Z Indexed on 2012/09/19 9:37 UTC
Read the original article Hit count: 191

Filed under:
|
|

I want to add an image to a Button (no imagebutton, as the particular button can either contain text or an image; plus the imagebutton has the same problem), while still retaining the original android-style button. So adding android:background in the XML doesn't cut it, as that will remove the android default button with rounded corners etc. (android.R.drawable.btn_default)

Is this in any way possible?

I think one way is to make a 9patch image for the button pressed (one for up and one for down) and onTouch Action_DOWN make a layered background drawable and put that onto the button, and doing the same thing but with another 9patch for onTouch Action_UP, but I think that will decrease the performance of the application substantially, as that will require quite a lot of resource reading and layer merging for all the button clicks (and for my application, that will be quite a lot). Is what I state above correct?

© Stack Overflow or respective owner

Related posts about android

Related posts about image