Jsrimac
Jsrimac

Reputation: 71

On Click of Floating Action Button the Icon has to be changed

When clicking the Floating Action button in Android, how can I change the icon image from "Play" to "Pause"?

Android screenshot

Upvotes: 0

Views: 1523

Answers (2)

Yann Huissoud
Yann Huissoud

Reputation: 1033

Those resources as many others are available on the google design website and should be put on your res drawable folder.

Then as mentioned by Kristiyan Varbanov and Keshav setImageResource is best practice

fab.setImageResource(R.drawable.ic_pause_dark);
fab.setImageResource(R.drawable.ic_play_dark);

Upvotes: 0

Kristiyan Varbanov
Kristiyan Varbanov

Reputation: 2509

Changing FloatingActionButton source:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            floatingActionButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_full_sad, context.getTheme()));
        } else {
            floatingActionButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_full_sad));
    }

Hope to help!

Upvotes: 1

Related Questions