---
title: "Standard Android Button with a different color"  
description: "Standard Android Button with a different color"  
author: "Anonymous User"  
published: 2015-06-04  
updated: 2015-06-04  
canonical: https://www.mindstick.com/forum/23283/standard-android-button-with-a-different-color  
category: "android"  
tags: ["android", "android controls"]  
reading_time: 4 minutes  

---

# Standard Android Button with a different color

I'd like to change the [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) of a [standard](https://www.mindstick.com/articles/23223/naming-convention-or-coding-standard) [Android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) slightly in [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) to better [match](https://www.mindstick.com/forum/159713/regex-match-attribute-in-an-html-code) a [client](https://www.mindstick.com/articles/23198/3-steps-to-ensure-that-your-client-portal-is-impeccable)'s branding.\
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](https://www.mindstick.com/forum/12745/how-do-i-use-webapi-rest-correctly-when-other-params-are-needed), 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](https://www.mindstick.com/articles/13148/discover-to-apply-make-up-like-a-professional-supermodel) some sort of color [transform](https://www.mindstick.com/interview/511/what-are-the-steps-to-transform-xml-into-html-using-xsl) to the button. Is there an easier way to go about changing a button's color than I'm doing?

## Replies

### Reply by Anonymous User

Put something like the following code in a file named custom_button.xml and then set background="@drawable/custom_button" in your button view:\

```
<?xml version="1.0" encoding="utf-8"?><selector    xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true" >        <shape>            <gradient                android:startColor="@color/yellow1"                android:endColor="@color/yellow2"                android:angle="270" />            <stroke                android:width="3dp"                android:color="@color/grey05" />            <corners                android:radius="3dp" />            <padding                android:left="10dp"                android:top="10dp"                android:right="10dp"                android:bottom="10dp" />        </shape>    </item>    <item android:state_focused="true" >        <shape>            <gradient                android:endColor="@color/orange4"                android:startColor="@color/orange5"                android:angle="270" />            <stroke                android:width="3dp"                android:color="@color/grey05" />            <corners                android:radius="3dp" />            <padding                android:left="10dp"                android:top="10dp"                android:right="10dp"                android:bottom="10dp" />        </shape>    </item>    <item>                <shape>            <gradient                android:endColor="@color/blue2"                android:startColor="@color/blue25"                android:angle="270" />            <stroke                android:width="3dp"                android:color="@color/grey05" />            <corners                android:radius="3dp" />            <padding                android:left="10dp"                android:top="10dp"                android:right="10dp"                android:bottom="10dp" />        </shape>    </item></selector>
```

\
You can also programmatically set the shade of the entire button.This will change the button colour rather than just the tint.If you start with a standard grey shaded button:\

```
button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
```

will give you a red shaded button,\

```
button.getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
```

will give you a green shaded button etc., where the first value is the colour in hex format.\
It works by multiplying the current button colour value by your colour value. I'm sure there's also a lot more you can do with these modes.


---

Original Source: https://www.mindstick.com/forum/23283/standard-android-button-with-a-different-color

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
