Clans / FloatingActionButton

Android Floating Action Button based on Material Design specification
Apache License 2.0
5.22k stars 1.13k forks source link

Setting colorfilter on icon on fab #43

Open adfleshner opened 9 years ago

adfleshner commented 9 years ago

I was curious if there was a way to set the color filter on a drawable on the fab.

I see a protected function getIconDrawable but like i said it is protected so im not able to use it. and get drawable returns null. I was just curious if there was any way to get it so I can update the filter.

Clans commented 9 years ago

Have you tried to set the color filter on the drawable and then set this drawable on the fab programmatically?

paulgavrikov commented 9 years ago

Not working either - has anyone updates on this?

Schachte commented 7 years ago

Any updates on this?

Croutonix commented 6 years ago

Normally there would be two ways of doing it:

FloatingActionButton fab= findViewById(R.id.fab);
fab.setColorFilter(color, PorterDuff.Mode.SRC_IN);

That doesn't work. You must use this instead:

FloatingActionButton fab = findViewById(R.id.fab);
Drawable icon = getDrawable(R.drawable.ic_icon);
icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
fab.setImageDrawable(icon);

It worked for me at least.