Now, this is more like it. After so many searching, I stumbled upon Folkert’s code wherein he was able to create gradient buttons in Android using just XML. That’s right! XML! I never liked having to create a colored button in Android using a 9 patch image. It is a hassle.

No matter what other developers say how easy it is to create a 9 patch image, doing it in XML is better. It is just a matter of copy-paste right? The sample codes for these gradient buttons contain only two color gradients.

The Android SDK permits a third color but for these XML codes, Folkert used only 2 colors. Now, it’s bye bye to those dull gray default Android buttons.

Here are the XML codes:
Blue

Red

Purple

Yellow

Black

All these buttons have the same text style so define a style in strings.xml:

And use it like this

Related Posts Plugin for WordPress, Blogger...