Clans / FloatingActionButton

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

Change the image of floating action menu in expanded state #340

Closed bkjbkjbnkj687698698 closed 7 years ago

bkjbkjbnkj687698698 commented 7 years ago

I want that to change the image of floating action menu in expanded state..Can i do that?

Fuhrmann commented 7 years ago

You could add a listener after the menu was toggled (setOnMenuToggleListener) or even use setOnMenuButtonClickListener. Inside of one of these listeners you can get the icon and set a new drawable, example:

final Drawable originalImage = mFab.getMenuIconView().getDrawable();
        mFab.setOnMenuButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mFab.isOpened()) {
                    // We will change the icon when the menu opens, here we want to change to the previous icon
                    mFab.close(true);
                    mFab.getMenuIconView().setImageDrawable(originalImage);
                } else {
                    // Since it is closed, let's set our new icon and then open the menu
                    mFab.getMenuIconView().setImageDrawable(drawableManager.getDrawable(getActivity(), R.drawable.ic_edit_24dp));
                    mFab.open(true);
                }
            }
        });

Result:

Screenshot