Learn how to implement a popup menu on views using these PopupMenu libraries.

1. QuickActionView

View that shows quick actions when long pressed, inspired by Pinterest.

QuickActionView is a View that shows quick actions when long pressed, inspired by Pinterest.

Popup Menu Tutorial

Below is a demo GIF:

Popup Menu Tutorial

Follow these steps to use it in your project:

Step 1: Add as a Gradle Dependency

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Then, add the library to your project build.gradle

dependencies {
    implementation 'com.github.Commit451:QuickActionView:latest.release.here'
}

Step 2: Basic Usage

See the sample app for usage within a normal layout, as well as within a list using RecyclerView. In the most basic usage:

View view = findViewById(R.id.your_view);
QuickActionView.make(this)
      .addActions(R.menu.actions)
      .register(view);

You can also create Actions at runtime:

Drawable icon = ContextCompat.getDrawable(this, R.drawable.ic_favorite_24dp);
String title = getString(R.string.action_favorite);
Action action = new Action(1337, icon, title);
QuickActionView.make(this)
        .addAction(action)
        //more configuring
        .register(view);

Step 3: Configuring the QuickActionView

QuickActionView can be customized globally, or on a per Action basis.

QuickActionView.make(this)
                .addActions(R.menu.actions)
                .setOnActionSelectedListener(mQuickActionListener)
                .setBackgroundColor(Color.RED)
                .setTextColor(Color.BLUE)
                .setTextSize(30)
                .setScrimColor(Color.parseColor("#99FFFFFF"))
                //etc
                .register(view);

Step 4: Configuring Action Items

Use the QuickActionConfig builder to create custom configurations for each action item you create.

//Give one of the quick actions custom colors
Action.Config actionConfig = new Action.Config()
        .setBackgroundColor(Color.BLUE)
        .setTextColor(Color.MAGENTA);

QuickActionView.make(this)
        .addActions(R.menu.actions)
        //the custom Action.Cofig will only apply to the addToCart action
        .setActionConfig(actionConfig, R.id.action_add_to_cart)
        .register(findViewById(R.id.custom_parent));

Listening for Events

You can hook into the interesting events a QuickActionView has:

QuickActionView.make(this)
      .addActions(R.menu.actions)
      .setOnActionSelectedListener(mQuickActionListener)
      .setOnShowListener(mQuickActionShowListener)
      .setOnDismissListener(mQuickActionDismissListener)
      .setOnActionHoverChangedListener(mOnActionHoverChangedListener)
      .register(view);

Reference

|2.|Read more here.|
|3.|Follow code author here.|

Read More.