Alpha background on FAB clicked

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 14:10:53

Liked your question...

This library won't allow u to set add button click event, you may have to change library code for your own, use this idea: Use Relatie or framelayout and add that black background or image behind FAB.

Now in library class FloatingActionsMenu.class find and comment this code:

//mAddButton.setOnClickListener(new OnClickListener()
//{
//  @Override
//  public void onClick(View v)
//  {
//      toggle();
//  }
//});

Then add this method in that class,

public void setAddButtonClickListener(OnClickListener listener)
{
mAddButton.setOnClickListener(listener);
}

Define click listener in your activity like

OnClickListener listener = new OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        if (floatingActionMenuButton.isExpanded())
        {//make the background visible
        }
        else
        {//make the background invisible
        }
        floatingActionMenuButton.toggle();
    }
};

and pass it to FAB

floatingActionMenuButton.setAddButtonClickListener(listener);

Build library and project, Hope this will help!

I found out this to be the easiest solution in my opinion, and it works perfectly :

fam.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
            dimmedBackground.setVisibility(View.VISIBLE);
        }

        @Override
        public void onMenuCollapsed() {
            dimmedBackground.setVisibility(View.GONE);
        }
    });

You need to wrap your activity in a FrameLayout. FrameLayout should have 2 childs

  • Your activity content
  • Another Framelayout containing FloatingActionsMenu

Here is the relevant code snippet.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.city.bytes.view.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- other content in the activity -->
</LinearLayout>

<FrameLayout
    android:id="@+id/frame_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white_overlay">
    <!--  floating action menu with buttons -->
</FrameLayout>

In your activity, change the alpha of frame_layout when FAB menu is clicked. I have also written a blog explaining it. http://www.rishabhsinghal.in/implement-floating-action-button-similar-to-inbox-by-gmail-or-evernote/

floatingActionMenu.setOnMenuToggleListener(
  new FloatingActionMenu.OnMenuToggleListener() { 
     @Override 
     public void onMenuToggle(boolean opened) {
         if(opened){
           //show backgroud
         }else{
           //hide backgroud
         }
     }
  });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!