FloatingActionButton icon indicating copy to clipboard operation
FloatingActionButton copied to clipboard

Setting colorfilter on icon on fab

Open adfleshner opened this issue 9 years ago • 4 comments

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.

adfleshner avatar May 12 '15 21:05 adfleshner

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

Clans avatar May 13 '15 04:05 Clans

Not working either - has anyone updates on this?

paulgavrikov avatar Jul 09 '15 10:07 paulgavrikov

Any updates on this?

Schachte avatar Mar 31 '17 03:03 Schachte

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.

Croutonix avatar Feb 11 '18 02:02 Croutonix