Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of Floating Action Button from Appcompat 22.2.0 programmatically

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

like image 564
user2410644 Avatar asked Jun 21 '15 15:06

user2410644


People also ask

How do you change the color of a floating action button?

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.

What is a floating action button?

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.


2 Answers

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

like image 184
Zuko Avatar answered Oct 02 '22 09:10

Zuko


Create a ColorStateList and set it as the background tint:

button.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}}, new int[]{color})); 
like image 41
tachyonflux Avatar answered Oct 02 '22 09:10

tachyonflux