How to implement easily modern material popup menu for Android

Jaewoong Eum
2 min readJan 23, 2019

--

Github — PowerMenu

When we are developing android applications, we should implement popup things like dialog or menu frequently. But on creating the menu, we can create only the fixed-items menu using an XML file and even it is not easy to modify or give some effects like a shadow, background or corner radius. It is really bothersome things to us whose have to more concentrate on core systems or architecture. So I published a library that the easiest way to implement modern popup.

How to implement

Before the implementation, we should add a dependency on the gradle file.

dependencies {
implementation "com.github.skydoves:powermenu:2.0.6"
}

Basic Example

Here is the basic example of the PowerMenu.
We can create an instance of the PowerMenu using PowerMenu.Builder.

We can add an instance of PowerMenuItem using the addItem method.
Here is how to create the PowerMenuItem. We should put the string value of menu title and we can put selected effect or icon optionally.

If the selected status is true, the item’s text and background color will be changed by your settings like below.

And we can listen that the menu is clicked. And change the selected menu.

And the last, show the nice popup like this.

Customizing Example

We can customize the menu item style using CustomPowerMenu and our customized adapter. Like below.

Firstable, we should create our item model class like below.

And next, we should create our own customized XML layout and adapter.
The custom Adapter should extends MenuBaseAdapter<YOUR_ITEM_MODEL>.

The last, create CustomPowerMenu and attach onMenuItemClickListener.

Dialog Example

Also, we can customize the PowerMenu looks like a dialog.

Below example is normal dialog. Dialogs are composed of a header, footer, and body.

And we can create a customized dialog like below.

You can reference more details about PowerMenu on below link.
Thank you for reading! Have a nice day.

--

--

Jaewoong Eum
Jaewoong Eum

Written by Jaewoong Eum

Senior Android Developer Advocate @ Stream 🥑 • GDE for Android • OSS engineer. Love psychology, magic tricks, and writing poems. https://github.com/skydoves

Responses (1)