Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

PowerMenu

> 编程语言
Open source

:fire: Powerful and modernized popup menu with fully customizable animations.

1.2K stars0 likes1 views
WebsiteGitHub

About

:fire: Powerful and modernized popup menu with fully customizable animations.

PowerMenu

:fire: PowerMenu is a modernized and fully customizable popup menu, which can be displayed on top of layouts.

Download

I really appreciate that PowerMenu has been used in more than 340,000+ projects all over the world.

Gradle

And add the dependency below to your module's build.gradle file:

gradle
dependencies {
  implementation "com.github.skydoves:powermenu:2.2.4"
}

Table of Contents

1. PowerMenu

2. Customizing Popup

3. Preference

4. Menu Effect

5. Dialogs

6. Anchor

7. Background

8. Avoid Memory leak

9. Functions

10. Lazy initialization in Kotlin

Usage

Basic example

This is a basic example on a screenshot. Here is how to create PowerMenu using PowerMenu.Builder.

…

We can add an item or an item list using PowerMenuItem class. This is how to initialize PowerMenuItem.

java
new PowerMenuItem("Travel");
new PowerMenuItem("Poetery", false); // item name, isSelected (default is false).
new PowerMenuItem("Art", R.drawable.icon_art) // item name, item menu icon.
new PowerMenuItem("Travel", R.drawable.icon_travel, true) // item name, item menu icon, isSelected .

The first argument is an item title, and the other is selected status.

If isSelected is true, the item's text and the background color will be changed by settings like below.

java
.setSelectedTextColor(Color.WHITE) // sets the color of the selected item text. 
.setSelectedMenuColor(ContextCompat.getColor(context, R.color.colorPrimary)) // sets the color of the selected menu item color.

OnMenuItemClickListener is for listening to the item click of the popup menu.

java
private OnMenuItemClickListener onMenuItemClickListener = new OnMenuItemClickListener() {
    @Override
    public void onItemClick(int position, PowerMenuItem item) {
        Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        powerMenu.setSelectedPosition(position); // change selected item
        powerMenu.dismiss();
    }
};

After implementing the listener, we should set using setOnMenuItemClickListener method.

java
.setOnMenuItemClickListener(onMenuItemClickListener)

The last, show the popup! Various show & dismiss methods.

java
powerMenu.showAsDropDown(view); // view is an anchor

Customizing Popup

We can customize item styles using CustomPowerMenu and your customized adapter.

Here is how to customize the popup item that has an icon.

Firstly, we should create our item model class.

java
public class IconPowerMenuItem {
    private Drawable icon;
    private String title;

    public IconPowerMenuItem(Drawable icon, String title) {
        this.icon = icon;
        this.title = title;
    }
 // --- skipped setter and getter methods
}

And we should create our customized XML layout and an adapter.

Custom Adapter should extend MenuBaseAdapter.

…

The last, create the CustomPowerMenu with the onMenuItemClickListener.

…
java
private OnMenuItemClickListener onIconMenuItemClickListener = new OnMenuItemClickListener() {
    @Override
    public void onItemClick(int position, IconPowerMenuItem item) {
        Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        iconMenu.dismiss();
    }
};

Preference

PowerMenu supports saving of the last selected menu and recovering as lifecycle.

Here is how to save and recover selected menu.

…

Here are the methods related to preference.

java
.getPreferenceName() // gets the preference name of PowerMenu.
.getPreferencePosition(int defaultPosition) // gets the saved preference position from the SharedPreferences.
.setPreferencePosition(int defaultPosition) // sets the preference position name for persistence manually.
.clearPreference() // clears the preference name of PowerMenu.

Menu Effect

We can give two types of circular revealed animation effect.

Here is how to create a menu effect simply.

java
.setCircularEffect(CircularEffect.BODY) // shows circular revealed effects for all body of the popup menu.
.setCircularEffect(CircularEffect.INNER) // Shows circular revealed effects for the content view of the popup menu.

Dialogs

We can create looks like dialogs using PowerMenu.

Here is an example of the normal dialog. Dialogs are composed of a header, footer, and body.

java
PowerMenu powerMenu = new PowerMenu.Builder(context)
           .setHeaderView(R.layout.layout_dialog_header) // header used for title
           .setFooterView(R.layout.layout_dialog_footer) // footer used for yes and no buttons
           .addItem(new PowerMenuItem("This is DialogPowerMenu", false)) // this is body
           .setLifecycleOwner(lifecycleOwner)
           .setAnimation(MenuAnimation.SHOW_UP_CENTER)
           .setMenuRadius(10f)
           .setMenuShadow(10f)
           .setWith(600)
           .setSelectedEffect(false)
           .build();

And we can create a customized dialog like below.

…

Anchor

We can show the popup menu as drop down to the anchor.

java
.showAsAnchorLeftTop(view) // showing the popup menu as left-top aligns to the anchor.
.showAsAnchorLeftBottom(view) // showing the popup menu as left-bottom aligns to the anchor.
.showAsAnchorRightTop(view) // using with .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) looks better
.showAsAnchorRightBottom(view) // using with .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) looks better
.showAsAnchorCenter(view) // using with .setAnimation(MenuAnimation.SHOW_UP_CENTER) looks better

or we can control the position of the popup menu using the below methods.

java
.getContentViewWidth() // return popup's measured width
.getContentViewHeight() // return popup's measured height

like this :

java
// showing the popup menu at the center of an anchor. This is the same using .showAsAnchorCenter.
hamburgerMenu.showAsDropDown(view, 
        view.getMeasuredWidth()/2 - hamburgerMenu.getContentViewWidth(), 
       -view.getMeasuredHeight()/2 - hamburgerMenu.getContentViewHeight());

Background

These are options for the background.

java
.setShowBackground(false) // do not showing background.
.setTouchInterceptor(onTouchListener) // sets the touch listener for the outside of popup.
.setFocusable(true) // makes focusing only on the menu popup.

Avoid Memory leak

Dialog, PopupWindow and etc.. have memory leak issue if not dismissed before activity or fragment are destroyed.

But Lifecycles are now integrated with the Support Library since Architecture Components 1.0 Stable released.

So we can solve the memory leak issue so easily.

Just use setLifecycleOwner method. Then dismiss method will be called automatically before activity or fragment would be destroyed.

java
.setLifecycleOwner(lifecycleOwner)

Lazy initialization in Kotlin

We can initialize the PowerMenu property lazily using powerMenu keyword and PowerMenu.Factory abstract class.

The powerMenu extension keyword can be used in Activity and Fragment.

kotlin
class MainActivity : AppCompatActivity() {

  private val moreMenu by powerMenu(MoreMenuFactory::class)
  
  //..

We should create a factory class which extends PowerMenu.Factory.

An implementation class of the factory must have a default(non-argument) constructor.

…

Functions

PowerMenu methods

…

Background methods

java
.setBackgroundAlpha(0.7f) // sets the alpha of the background.
.setBackgroundColor(Color.GRAY) // sets the color of the background.
.setShowBackground(false) // sets the background is showing or not.
.setOnBackgroundClickListener(onClickListener) // sets the background click listener of the background.

Show & Dismiss

…

Find this library useful? :heart:

Support it by joining stargazers for this repository. :star:

And follow me for my next creations!

License

xml
Copyright 2017 skydoves

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaandroidandroid-libraryandroid-menudialog

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言