Popup Menu Libraries
Learn how to implement a popup menu on views using these PopupMenu libraries.
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.
Below is a demo GIF:
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):
Then, add the library to your project build.gradle
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);