Change image Floating Action Button Android

pippo10 picture pippo10 · May 26, 2015 · Viewed 92.8k times · Source

I used this library https://github.com/futuresimple/android-floating-action-button. How can I change the image of the main button? I want to change the button image right after selecting one of the smaller buttons.

Answer

Alex Bravo picture Alex Bravo · Aug 18, 2015

From https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html

As this class descends from ImageView, you can control the icon which is displayed via setImageDrawable(Drawable).

Or you can use setImageResource():

fab.setImageResource(R.drawable.ic_shopping_cart_white);