content: package com.ajaysinghdewari.floatingactionbuttonmenu.activities;
  
  import android.animation.Animator;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.widget.LinearLayout;
  
  import com.ajaysinghdewari.floatingactionbuttonmenu.R;
  
  public class MainActivity extends AppCompatActivity {
  
      FloatingActionButton fab, fab1, fab2, fab3;
      LinearLayout fabLayout1, fabLayout2, fabLayout3;
      View fabBGLayout;
      boolean isFABOpen = false;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          fabLayout1 = (LinearLayout) findViewById(R.id.fabLayout1);
          fabLayout2 = (LinearLayout) findViewById(R.id.fabLayout2);
          fabLayout3 = (LinearLayout) findViewById(R.id.fabLayout3);
          fab = (FloatingActionButton) findViewById(R.id.fab);
          fab1 = (FloatingActionButton) findViewById(R.id.fab1);
          fab2 = (FloatingActionButton) findViewById(R.id.fab2);
          fab3 = (FloatingActionButton) findViewById(R.id.fab3);
          fabBGLayout = findViewById(R.id.fabBGLayout);
  
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  if (!isFABOpen) {
                      showFABMenu();
                  } else {
                      closeFABMenu();
                  }
              }
          });
  
          fabBGLayout.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  closeFABMenu();
              }
          });
      }
  
      private void showFABMenu() {
          isFABOpen = true;
          fabLayout1.setVisibility(View.VISIBLE);
          fabLayout2.setVisibility(View.VISIBLE);
          fabLayout3.setVisibility(View.VISIBLE);
          fabBGLayout.setVisibility(View.VISIBLE);
          fab.animate().rotationBy(180);
          fabLayout1.animate().translationY(-getResources().getDimension(R.dimen.standard_55));
          fabLayout2.animate().translationY(-getResources().getDimension(R.dimen.standard_100));
          fabLayout3.animate().translationY(-getResources().getDimension(R.dimen.standard_145));
      }
  
      private void closeFABMenu() {
          isFABOpen = false;
          fabBGLayout.setVisibility(View.GONE);
          fab.animate().rotation(0);
          fabLayout1.animate().translationY(0);
          fabLayout2.animate().translationY(0);
          fabLayout3.animate().translationY(0);
          fabLayout3.animate().translationY(0).setListener(new Animator.AnimatorListener() {
              @Override
              public void onAnimationStart(Animator animator) {
  
              }
  
              @Override
              public void onAnimationEnd(Animator animator) {
                  if (!isFABOpen) {
                      fabLayout1.setVisibility(View.GONE);
                      fabLayout2.setVisibility(View.GONE);
                      fabLayout3.setVisibility(View.GONE);
                  }
              }
  
              @Override
              public void onAnimationCancel(Animator animator) {
  
              }
  
              @Override
              public void onAnimationRepeat(Animator animator) {
  
              }
          });
      }
  
      @Override
      public void onBackPressed() {
          if (isFABOpen) {
              closeFABMenu();
          } else {
              super.onBackPressed();
          }
      }
  }
  