I want to set a transparent background layer when I click on the floating action menu.

自古美人都是妖i 提交于 2019-12-06 19:54:28

Try this.

floatingActionMenuButton.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
            @Override
            public void onMenuToggle(boolean opened) {
                if (opened) {
                    //menu opened
                } else {
                    //menu closed
                }
            }
        });

use setBackgroundResource or setBackgroundColor. I think first is pretty simple.

Second one takes an int as an argument. So, just convert your hex color (for example #55000000) into decimal and it will work as well.

I had the same issue and i fixed it in following way.

I added a relative layout which will match parent in both width and height. Set its background color to black and set alpha to your required opacity.

<RelativeLayout
    android:id="@+id/obstructor"
    android:visibility="invisible"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:alpha="0.75"
    android:background="@android:color/black">

</RelativeLayout>

And then on the menu item expanded and collapsed make this visible and invisible.

mFabMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
final RelativeLayout obstrucuterView = (RelativeLayout) findViewById(R.id.obstructor);
obstrucuterView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (obstrucuterView.getVisibility() == View.VISIBLE) {
            mFabMenu.collapse();
            return true;
        }
        return false;
    }
});

mFabMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
    @Override
    public void onMenuExpanded() {
        if (obstrucuterView.getVisibility() == View.INVISIBLE)
            obstrucuterView.setVisibility(View.VISIBLE);
    }

    @Override
    public void onMenuCollapsed() {
        if (obstrucuterView.getVisibility() == View.VISIBLE)
            obstrucuterView.setVisibility(View.INVISIBLE);
    }
});

Hope this helps.

There is another custom library which is more advanced than what you are using right now.

Get it here Clans floating Action Button

Set this to true and it will solve your problem. Do let me know if it helps

fabPlusButton.setClosedOnTouchOutside(true);

If you are using Clans floating Action Button then perhaps fab:menu_backgroundColor might be something that you could have a look at if it satisfies your use-case. ofcourse the layout width and height should both match parent (This solution has worked for me)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!