Standard Android Button with a different color

后端 未结 20 3306
误落风尘
误落风尘 2020-11-21 23:43

I\'d like to change the color of a standard Android button slightly in order to better match a client\'s branding.

The best way I\'ve found to do this so far is to c

20条回答
  •  梦毁少年i
    2020-11-22 00:14

    Following on from Tomasz's answer, you can also programmatically set the shade of the entire button using the PorterDuff multiply mode. 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.

提交回复
热议问题