I would like to know how to change the Floating Action Button color from the Support library 22.2.0 ? I've tried
button.setBackgroundColor(color);
but clearly, this changes the drawable of the button and it turns to a square.
Now I wonder how to change the color but just the color, without touching the shape?
Thanks in advance
To change background color of Floating Action Button in Kotlin Android, set the backgroundTint attribute (in layout file) or backgroundTintList property (in Kotlin file) of FAB with the required color.
A floating action button (FAB) is a circular button that triggers the primary action in your app's UI. This page shows you how to add the FAB to your layout, customize some of its appearance, and respond to button taps.
Maybe late but could help.
fab.setBackgroundTintList(ColorStateList.valueOf(Color .parseColor("#33691E")));
and parse the actual color code from a list of colors You can find here
Create a ColorStateList
and set it as the background tint:
button.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}}, new int[]{color}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With