views:

549

answers:

1

I have to create a colored button with gradient fill(starting from the middle of the button along Y axis). If I set the background property of the button to the color I want, I lose the rounded look and feel of a button and also the gradient fill(It looks like a TextView with a background).

Also, I want this color to change when the user depresses the button. Can i specify this via selector XMLs(Color State Lists)?

Any tutorials or links that can help me here is appreciated.

Thanks.

A: 

http://stackoverflow.com/questions/2173936/how-to-set-background-color-of-a-view

You will need to define a custom StateListDrawable resource, cloned perhaps from the one Android uses for buttons by default, where you change the nine-patch images to be gradients. You might be able to define those gradients in XML, which would mean they would stretch nicely.

CommonsWare