fab fab - 1 year ago 159
Android Question

Android tint icon in FloatingActionButton

How to tint an icon resource image used with FloatingActionButton, I tried

favoriteFab.setColorFilter(R.color.yellow, PorterDuff.Mode.OVERLAY);
but no success.

Answer Source

You can set the color tint of the drawable like this.



mFAB = (FloatingActionButton) findViewById(R.id.fab);
mFAB.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Snackbar.make(v, "Yummy snackbar", LENGHT_LONG).show();

Update: Since getColor has been deprecated you should use ContextCompat instead. Use the following e.g:

mFAB.getDrawable().mutate().setTint(ContextCompat.getColor(this, R.color.colorAccent));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download