Standard Android Button with a different color

后端 未结 20 3249
误落风尘
误落风尘 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条回答
  • 2020-11-22 00:23

    Per material design guidelines, you need to use the style like below code

    <style name="MyButton" parent="Theme.AppCompat.Light>
        <item name="colorControlHighlight">#F36F21</item>
        <item name="colorControlHighlight">#FF8D00</item>
    </style>
    

    and in layout add this property to your button

        android:theme="@style/MyButton"
    
    0 讨论(0)
  • 2020-11-22 00:24

    An easy way is to just define a custom Button class which accepts all the properties that you desire like radius, gradient, pressed color, normal color etc. and then just use that in your XML layouts instead of setting up the background using XML. A sample is here

    This is extremely useful if you have a lot of buttons with same properties like radius, selected color etc. You can customize your inherited button to handle these additional properties.

    Result (No Background selector was used).

    Normal Button

    Normal Image

    Pressed Button

    enter image description here

    0 讨论(0)
提交回复
热议问题