The PowerMenu can be fully configured and used for context-sensitive dialogs.

A powerful and easiest way to implement modern material popup menu

Cradle

And insert the dependency code into your module’s build.gradle file.

Dependencies {
Version com.github.skydoves:powermenu:2.1.7
}.

Use

Basic example

This is the most important example of the screenshot. Here you will learn how to create a PowerMenu with PowerMenu.

PowerMenu powerMenu = new PowerMenu.Builder(context)
.addItemList(list) // The list includes Novel, Poerty, Art
.addItem(new PowerMenuItem(Journals, false)) // Add item
.addItem(new PowerMenuItem(Journey, False)) // …and list of items.
.setAnimation(MenuAnimation.SHOWUP_TOP_LEFT) // Starting point of the animation (TOP | LEFT).
.setMenuRadius(10f) // Sets the angular radius.
.setMenuShadow(10f) // Sets the shadow.
.setTextColor(KontextCompat.getColor(Context, R.color.md_grey_800))).
.setTextGravity (Gravity.CENTER)
.setTextTypeface (Typeface.create (sans-serif medium, Typeface.BOLD))
.setSelectedTextColor (Color.white)
.setMenuColor (Color.white).white)
.setSelectedMenuColor(ContextCompat.getColor(Context, R.color.colorPrimary))
.setOnMenuItemClickListener(onMenuItemClickListener)
.build() ;

We can add an item or a list of items using the PowerMenuItem class. How to initialize the PowerMenuItem.

new PowerMenuItem(Travel); new PowerMenuItem(Poetry, wrong); // Item name, isSelected (wrong by default). 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 the title of the item and the second is the selected status.

If isSelected is true, the element text and background color are changed according to the parameters below.

.setSelectedTextColor (Color.WHITE) // sets the text color of the selected element.
.setSelectedMenuColor (KontextCompat.getColor(Context, R.color.colorPrimary)). // sets the color of the selected menu item.

The OnMenuItemClickListener is designed to listen to a click on a contextual menu item.

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

After the implementation of the listener it is necessary to install the setOnMenuItemClickListener method.

.setOnMenuItemClickListener(onMenuItemClickListener)

Let me finally see the pop-up window! Different methods of exposure and recording.

powerMenu.showAsDropDown(display); // Display is anchor.

We can customize item sizes using the CustomPowerMenu and your custom adapter.

Here you will learn how to create an icon pop-up window.

A powerful and easiest way to implement modern material popup menu

A powerful and easiest way to implement modern material popup menu

First we have to create our class of element models.

IconPowerMenuItem public class {
private drawable icon ;
private snare head ;

public IconPowerMenuItem(icon to draw, string title) {
this.icon = icon;
this.title = title;
}
// — missed setter and gob methods
}

And we need to create our own customizable layout and XML adapter.

The user adapter must extend the MenuBaseAdapter.

The IconMenuAdapter public class extends the IconMenuAdapter {

@ Inversion
public view getView(int index, view View, ViewGroup ViewGroup) {
last context = viewGroup.getContext() ;

if(view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.item_icon_menu, viewGroup, false);
}.

IconPowerMenuItem input = (IconPowerMenuItem) getItem(index);
final ImageView icon = view.findViewById(R.id.item_icon);
icon.setImageDrawable(item).getIcon()));
final TextView title = view.findViewById(R.id.item_title);
title.setText(item.getTitle());
return super.getView(index, viewGroup);
}
}.

Finally, create the CustomPowerMenu with the onMenuItemClickListener.

CustomPowerMenu customPowerMenu = new CustomPowerMenu.Builder<>(context, new IconMenuAdapter())
.addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable).ic_wechat), WeChat)).
.addItem(new IconPowerMenuItem(contextCompat.getDrawable(context, R.drawable.ic_facebook), Facebook)))
.addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable.ic_twitter), Twitter))
.addItem(new IconPowerMenuItem(ContextCompat.getDrawable(context, R.drawable.ic_line), Line))
.setOnMenuItemClickListener(onIconMenuItemClickListener)
.setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT)
.setMenuRadius(10f)
.setMenuShadow(10f)
;

overwrite private OnMenuItemClickListener onIconMenuItemClickListener() {
@
public space onItemClick(int position, IconPowerMenuItem item) {
Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
iconMepz.dismiss();
}.
} ;

Preference

With PowerMenu you can save the last selected menu and restore it as a lifecycle.

Learn how to back up and restore the selected menu.

gives a new PowerMenu.Builder(context)
// automatically saves the position when the
menu is selected // If we set the same preferred names in other PowerMenus, they share the same memory position.
.setPreferenceName (HamburgerPowerMenu)

// automatically calls the listener who has stored the position arguments according to the life cycle rule.
// Life cycle rules should be ON_CREATE, ON_START or ON_RESUME.
// In the following codes, onCreate is called the onMenuClickListener when creating a lifecycle.
.setLifecycleOwner(life cycleOwner)
.setInitializeRule(Lifecycle.Event.ON_CREATE, 0) // Lifecycle.Event and default position.
— jumps —

Here are the methods related to the preferences.

.getPreferenceName() // displays the desired PowerMenu name.
.getPreferencePosition(int defaultPosition) // retrieves the preferred position stored in Shared Preferences.
.setPreferencePosition(int defaultPosition) // retrieves the preferred position to be saved manually.
.clearPreference() // clears the preferred name from the PowerMenu.

We can detect two types of circular animation effects.

A powerful and easiest way to implement modern material popup menu

52637462-9a878400-2f12-1-935d-189c518fe435 That’s how easy it is to create a menu effect.

.setCircularEffect (CircularEffect.BODY) // displays the detected whole-body circular effects from the context menu.
.setCircularEffect (CircularEffect.INNER) // Displays the effects detected cyclically for the content of the context menus.

Dialogues

With PowerMenu we can create dialogues that look like this.

A powerful and easiest way to implement modern material popup menu

A powerful and easiest way to implement modern material popup menu

Here is an example of a normal dialogue. Dialogues consist of a head, foot and body.

PowerMenu powerMenu = new PowerMenu.Builder(context)
.setHeaderView(R.layout.layout_dialog_header) // Header used for
.setFooterView(R.layout.layout_dialog_footer) // Footer used for
buttons .addItem (new PowerMenuItem (this is DialogPowerMenu, false)) // this is the most important part
.setLifecycleOwner
.setAnimation(MenuAnimation.SHOW_UP_CENTER)
.setMenuRadius(10f)
.setMenuShadow(10f)
.setMet(600)
.setSelectedEffect(false)
.build() ;

And we can create a customizable dialog as shown below.

CustomPowerMenu customPowerMenu = new CustomPowerMenu.Builder<>(context, new CustomDialogMenuAdapter())
setHeaderView(R.layout.layout_custom_dialog_header) // Title used for titles
.setFooterView(R.layout.layout_custom_dialog_footer) // the header used for the Read Next and Close buttons
// the body
.addItem(new NameCardMenuItem(ContextCompat.getDrawable.face3), Sophie, context.getString(R.string.board3)))))).
.setLifecycleOwner(life cycleOwner)
.setAnimation(MenuAnimation.SHOW_UP_CENTER)
.setMet(800)
.setMenuRadius(10f)
.setMenuShadow(10f)
.build() ;

Fixture

We can show the context menu as being at anchor.

A powerful and easiest way to implement modern material popup menu

.showAsAnchorLeftTop(view) // displays the context menu as the left armor alignment at the top. .showAsAnchorLeftBottom(view) // displays the context menu as the left armor alignment at the top..showAsAnchorRightTop(view) // Use with .setAnimation(AnimationMenu).SHOWUP_TOP_RIGHT) gives better results.showAsAnchorRightBottom(view) // Use with .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) looks better.showAsAnchorCenter(view) // Using with .setAnimation(MenuAnimation.SHOWUP_TOP_RIGHT) looks better.showAsAnchorCenter(view) // Use with .setAnimation(MenuAnimation.SHOW_UP_CENTER) looks better.showAnchorCenter(view) // Use with .setAnimation(MenuAnimation.SHOW_UP_CENTER) looks better.

or we can check the position of the context menu using the following methods.

.getContentViewWidth() // displays the measured width of the pop-up window
.getContentViewHeight() // displays the measured height of the pop-up window

So, uh… :

// display the context menu in the center of the anchor. Same goes for the .show anchor center.
– hamburger menu.showAsDropDown(view,
view.getMeasuredWidth()/2 – hamburger menu.getContentViewWidth(),
– view.getMeasuredHeight()/2 – hamburger menu.getContentViewHeight() ;

 

Background

These are background options.

.setShowBackground(false) // does not display the background.
.setTouchInterceptor (onTouchListener) // specifies the touch receiver for pop-ups.
.setFocusable(true) // focuses only on the context menu.

Avoiding memory leaks

Dialog, PopupWindow etc. have a memory leak problem if they are not repaired before the activity or fragment is destroyed.

But Lifecycles is now integrated in the supporting library because Architecture Components 1.0 Stable has been released.

This way we can easily solve the problem of the memory leak.

Just use the setLifecycleOwner method. The release method is then automatically called up before the activity or fragment is destroyed.

.setLife cycle owner

Lazy initialization in the Kotlin

We can initialize the PowerMenu property with the keyword PowerMenu and the abstract class PowerMenu.Factory lazy.

The PowerMenu extension keyword can be used in Activity and Fragmentation.

Main activity of the class : AppCompatActivity() {

private fall moreMenu after powerMenu (MoreMenuFactory::Class)

//..

We need to create a factory class that expands the PowerMenu.

The factory equipment class must have a standard (non-standard) manufacturer.

PlusClassMenuFactory : Power menu. Factory() {)

redefine a playful creation (context: context, life cycle: owner of the life cycle?) PowerMenu {return createPowerMenu(context) {addItem(PowerMenuItem(Novel, true)))addItem(PowerMenuItem(Poetry, false))setAutoDismiss(true)setLifecycleOwner(life cycle)setAnimation.SHOWUP_TOP_LEFT)setTextColor(ContextCompat.getColor(context, R).).color.md_grey_800))setSizeText(12)setGravityText(Gravity.CENTER)setTypefaceText(Typeface.create(without serif-medium, Typeface.BOLD))setColorTextSelected(Color.WHITE)setMenuColor(Color.WHITE)setInitializeRule(Lifecycle.Event.CREATE_ON, 0)}}}}.

Functions

.addItemList(list) // Add PowerMenuItem list.
.addItem (new PowerMenuItem (logs, lie down)) // Add PowerMenuItem
.addItem (3, new PowerMenuItem (travel, lie down)) // Add PowerMenuItem in position 3.
.setLifecycleOwner // Set LifecycleOwner to prevent memory leaks.
.setWith(300) // set the width of the pop-up window.
.setHeight(400) // set the size of the popup window.
.setMenuRadius(10f) // set the radius of the pop-up angle.
.setMenuShadow(10f) // sets the size of the shadow in the pop-up window.
.setDivider(new ColorDrawable(ContextCompat.getColor(context, R.color.md_blue_grey_300)))). // sets the separator.
.setDividerHeight(1) // sets the height of the separator.
.setAnimation(MenuAnimation.FADE) // sets the popup animation. It starts when a pop-up window appears.
.setTextColor(ContextCompat.getColor(context, R.color.md_grey_800)) // sets the default text color for articles.
.setTextSize(12) // sets the text size of the
element .setTextGravity(Gravity.CENTER) // sets the text gravity of the
element .setTextTypeface(font.create(sans-serif medium, font.BOLD)). // sets the text font of the
.setSelectedTextColor element (Color.WHITE) // sets the text color of the selected element.
.setMenuColor (Color.WHITE) // sets the color of the menu item.
.setSelectedMenuColor (KontextCompat.getColor(Context, R.color.colorPrimary)). // sets the color of the selected menu item.
.setSelectedEffect(false) // sets the selected effects that change the color of the selected menu item.
.setOnMenuItemClickListener // sets the listener to click items.
.setOnDismissListener (OnDismedListener onDismissListener) // sets the Delete Listener menu item.
.setHeaderView // sets the list title display in the context menu.
.setHeaderView(int layout) // Sets the title display of the context menu using the layout.
.setFooterView(view view) // Sets the title display for the context menu list title.
.setFooterView(int layout) // Sets the lower context menu footer display using the layout.
.setSelection(int position) // Sets the selected position of the context menu. It can be used as a scroll position.
.getSelectedPosition() // retrieves the selected position of the item. if not previously selected, -1.
.getHeaderView() // returns the title of the context menu list.
.getFooterView() // returns the title of the context menu list.
.getMenuListView() // takes the ListView view from the context menu.

Basic methods

.setBackgroundAlpha(0.7f) // set the alpha background…setBackgroundColor(Color.GRAY) // set the background color…setShowBackground(false) // set the background color. .setOnBackgroundClickListener(onClickListener) // set the background click of the background listener.

Aim and walk

.showAsDropDown; // display the context menu as a drop-down list to the anchor.
.showAsDropDown; // display popup menu as drop-down list to anchor with x-off and y-off.
.showAtCenter; // display of the context menu in the middle.
.showAtCenter(show layout, 0, 0); // display of a popup menu centered on x-off and y-off.
.showAtLocation(show anchor, int xOff, int yOff) // Display context menu centered on x-off and y-off.
.showAtLocation(show anchor, int xOff, int yOff) // Displays context menu centered on anchor alignment by gravity.
.isShowing(); // Show or not show context menu.
.isShowing(); // Closes the pop-up window.

GitHub

You May Also Like

🥇 Calculate the Cost of a Product in Excel  Step by Step Guide ▷ 2020

If you want to sell a product or offer a service to…

🥇 MICROSOFT POWERPOINT  What is it? + Alternatives ▷ 2020

One of the advantages of using Office software packages is that you…

Pytorch Image Augmentation using Transforms.

In-depth learning models generally require a lot of data for learning. In…

Fix: Google Photos not backing up on iPhone

For many iPhone users, Google Photos remains the first choice, even though…