I would like to know how to change the color of a Floating Action Button with animation, I tried it ObjectAnimator
but it doesn't change.
That is to say that after clicking I change the color of the button, this is my code:
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator.ofArgb(floatingActionButton, "Color").start();
}
});
programmatically it would be through a ColorStateList and the setBackgroundTintList() method :
It is very important to define the Alpha so that your color changes!
You can also upload your color from
colors.xml
:so you would change the color like this:
There are also 2 ways via property
app:backgroundTint
or just define your button image with another color viaandroid:src
:You can even define your own image and change the color with
app:backgroundTint
, but make sure your image has the proper transparency.If you want to do it by code you can put this in the button event (example):