Standard Android Button with a different color

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2009-10-05T18:23:30Z Indexed on 2010/04/25 10:33 UTC
Read the original article Hit count: 314

Filed under:
|
|

I'd like to change the color of a standard Android button slightly in order to better match a client's branding. For example, see the "Find a Table" button for the OpenTable application:

alt text

The best way I've found to do this so far is to change the Button's drawable to the following drawable located in res/drawable/red_button.xml:

<?xml version="1.0" encoding="utf-8"?>    
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/red_button_pressed" />
    <item android:state_focused="true" android:drawable="@drawable/red_button_focus" />
    <item android:drawable="@drawable/red_button_rest" />
</selector>

But doing that requires that I actually create three different drawables for each button I want to customize (one for the button at rest, one when focused, and one when pressed). That seems more complicated and non-DRY than I need.

All I really want to do is apply some sort of color transform to the button. Is there an easier way to go about changing a button's color than I'm doing?

© Stack Overflow or respective owner

Related posts about android

Related posts about layout