Standard Android Button with a different color

后端 未结 20 3518
误落风尘
误落风尘 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:19

    This is my solution which perfectly works starting from API 15. This solution keeps all default button click effects, like material RippleEffect. I have not tested it on lower APIs, but it should work.

    All you need to do, is:

    1) Create a style which changes only colorAccent:

    
    

    I recommend using ThemeOverlay.AppCompat or your main AppTheme as parent, to keep the rest of your styles.

    2) Add these two lines to your button widget:

    style="@style/Widget.AppCompat.Button.Colored"
    android:theme="@style/Facebook.Button"
    

    Sometimes your new colorAccent isn't showing in Android Studio Preview, but when you launch your app on the phone, the color will be changed.


    Sample Button widget

提交回复
热议问题