Color the standard Android Button

If you would like to color the standard Android button, like in the app “OpenTable” here is the code how you can do that.

See the app “OpenTable” Screenshot to the right.
At the bottom there is an standard Android button with color red.

At the moment i had not found to do this with xml syntax.
If anyone know how to do this via xml, please leave a comment.

Here is the way how you can color the standard Android button programatically:

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.

0xFF is fix and afterwards you have do write the hex code for your color.
You can find HTML Codes on the site “HTML Color Codes” !
Write down the code without the # and use it in setColorFilter(0xFF and your HTML code!