content: package com.yalantis.contextmenu.sample;
  
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.drawable.BitmapDrawable;
  import android.os.Bundle;
  import android.support.v4.app.DialogFragment;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v7.app.ActionBarActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.jinlin.yalantis.R;
  import com.yalantis.contextmenu.lib.ContextMenuDialogFragment;
  import com.yalantis.contextmenu.lib.MenuObject;
  import com.yalantis.contextmenu.lib.interfaces.OnMenuItemClickListener;
  import com.yalantis.contextmenu.lib.interfaces.OnMenuItemLongClickListener;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class ContextMenuActivity extends ActionBarActivity implements OnMenuItemClickListener,
          OnMenuItemLongClickListener{
  
      private FragmentManager fragmentManager;
      private DialogFragment mMenuDialogFragment;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_context_menu);
          fragmentManager = getSupportFragmentManager();
          initToolbar();
          mMenuDialogFragment = ContextMenuDialogFragment.newInstance((int) getResources().getDimension(R.dimen.tool_bar_height), getMenuObjects());
          addFragment(new MainFragment(), true, R.id.container);
      }
  
      private List<MenuObject> getMenuObjects() {
          // You can use any [resource, bitmap, drawable, color] as image:
          // item.setResource(...)
          // item.setBitmap(...)
          // item.setDrawable(...)
          // item.setColor(...)
          // You can set image ScaleType:
          // item.setScaleType(ScaleType.FIT_XY)
          // You can use any [resource, drawable, color] as background:
          // item.setBgResource(...)
          // item.setBgDrawable(...)
          // item.setBgColor(...)
          // You can use any [color] as text color:
          // item.setTextColor(...)
          // You can set any [color] as divider color:
          // item.setDividerColor(...)
  
          List<MenuObject> menuObjects = new ArrayList<>();
  
          MenuObject close = new MenuObject();
          close.setResource(R.drawable.icn_close);
  
          MenuObject send = new MenuObject("Send message");
          send.setResource(R.drawable.icn_1);
  
          MenuObject like = new MenuObject("Like profile");
          Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.icn_2);
          like.setBitmap(b);
  
          MenuObject addFr = new MenuObject("Add to friends");
          BitmapDrawable bd = new BitmapDrawable(getResources(),
                  BitmapFactory.decodeResource(getResources(), R.drawable.icn_3));
          addFr.setDrawable(bd);
  
          MenuObject addFav = new MenuObject("Add to favorites");
          addFav.setResource(R.drawable.icn_4);
  
          MenuObject block = new MenuObject("Block user");
          block.setResource(R.drawable.icn_5);
  
          menuObjects.add(close);
          menuObjects.add(send);
          menuObjects.add(like);
          menuObjects.add(addFr);
          menuObjects.add(addFav);
          menuObjects.add(block);
          return menuObjects;
      }
  
      private void initToolbar() {
          Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
          TextView mToolBarTextView = (TextView) findViewById(R.id.text_view_toolbar_title);
          setSupportActionBar(mToolbar);
          getSupportActionBar().setHomeButtonEnabled(true);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          getSupportActionBar().setDisplayShowTitleEnabled(false);
          mToolbar.setNavigationIcon(R.mipmap.btn_back);
          mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  onBackPressed();
              }
          });
          mToolBarTextView.setText("Samantha");
      }
  
      protected void addFragment(Fragment fragment, boolean addToBackStack, int containerId) {
          invalidateOptionsMenu();
          String backStackName = fragment.getClass().getName();
          boolean fragmentPopped = fragmentManager.popBackStackImmediate(backStackName, 0);
          if (!fragmentPopped) {
              FragmentTransaction transaction = fragmentManager.beginTransaction();
              transaction.add(containerId, fragment, backStackName)
                      .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
              if (addToBackStack)
                  transaction.addToBackStack(backStackName);
              transaction.commit();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(final Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu_context, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case R.id.context_menu:
                  if (fragmentManager.findFragmentByTag(ContextMenuDialogFragment.TAG) == null) {
                      mMenuDialogFragment.show(fragmentManager, ContextMenuDialogFragment.TAG);
                  }
                  break;
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onBackPressed() {
          if (fragmentManager.getBackStackEntryCount() == 1) {
              finish();
          } else {
              super.onBackPressed();
          }
      }
  
      @Override
      public void onMenuItemClick(View clickedView, int position) {
          Toast.makeText(this, "Clicked on position: " + position, Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onMenuItemLongClick(View clickedView, int position) {
          Toast.makeText(this, "Long clicked on position: " + position, Toast.LENGTH_SHORT).show();
      }
  }
  