-
Notifications
You must be signed in to change notification settings - Fork 227
PopMenu_en
Provides a lightweight menu that can attach to a View to expand or be displayed directly in the center of the screen for simple selection.
You can also use other themes to enrich the menu's style:
PopMenu.show(new String[]{"Add", "Edit", "Delete", "Share"});
You can also use List<CharSequence>
to set the menu content.
PopMenu.show(new String[]{"Add", "Edit", "Delete", "Share"})
.setOnIconChangeCallBack(new OnIconChangeCallBack<PopMenu>(true) {
@Override
public int getIcon(PopMenu dialog, int index, String menuText) {
switch (index) {
case 0:
return R.mipmap.img_dialogx_demo_add;
case 1:
return R.mipmap.img_dialogx_demo_edit;
case 2:
return R.mipmap.img_dialogx_demo_delete;
case 3:
return R.mipmap.img_dialogx_demo_share;
default:
return 0;
}
}
});
PopMenu.show(view, new String[]{"Option 1", "Option 2", "Option 3"})
.setOverlayBaseView(true);
Example code:
PopMenu.show(view, new String[]{"Option 1", "Option 2", "Option 3"})
.setOverlayBaseView(false)
.setAlignGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
PopMenu.show(new String[]{"Option 1", "Option 2", "Option 3"})
.setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
@Override
public boolean onClick(PopMenu dialog, CharSequence text, int index) {
btnSelectMenu.setText(text);
return false;
}
});
You can also use the getSelectIndex()
method to get the index of the selected menu item, or getSelectMenuText()
to get the text of the selected menu item.
Set a menu item as selected (the menu background will show a selected state).
.setPressedIndex(index)
After setting, the menu item at the specified index will show a selected state (background color) when the menu is displayed.
To monitor the lifecycle of a dialog, you can implement the .setDialogLifecycleCallback(...)
interface. It's recommended to use the build()
method to construct the dialog:
PopMenu.build()
.setMenuList(new String[]{"Option 1", "Option 2", "Option 3"})
.setDialogLifecycleCallback(new DialogLifecycleCallback<PopMenu>() {
@Override
public void onShow(PopMenu dialog) {
super.onShow(dialog);
}
@Override
public void onDismiss(PopMenu dialog) {
super.onDismiss(dialog);
}
})
.show();
PopMenu also supports Lifecycle. You can get the Lifecycle object using .getLifecycle()
.
You can also handle lifecycle events by overriding them when creating an instance using new
, for example:
// Event overriding demonstration
new PopMenu() {
@Override
public void onShow(PopMenu dialog) {
//...
tip("onShow");
}
@Override
public void onDismiss(PopMenu dialog) {
//...
tip("onDismiss");
}
}
You can also use the methods .onShow(DialogXRunnable)
and .onDismiss(DialogXRunnable)
to handle lifecycle transactions, for example:
PopMenu.show(...)
.onShow(new DialogXRunnable<PopMenu>() {
@Override
public void run(PopMenu dialog) {
//PopMenu show!
}
})
.onDismiss(new DialogXRunnable<PopMenu>() {
@Override
public void run(PopMenu dialog) {
//PopMenu dismiss!
}
});
To implement a custom layout in the dialog, first prepare your custom layout file, then build using the following method:
PopMenu.build()
.setCustomView(new OnBindView<PopMenu>(R.layout.layout_custom_view) {
@Override
public void onBind(PopMenu dialog, View v) {
}
})
.setMenuList(new String[]{"Option 1", "Option 2", "Option 3"})
.show();
In the callback parameters, v
is the instantiated component of your given layout file. You can instantiate other sub-layout components using v.findViewById(resId)
and set their functionality and event callbacks in the onBind
method.
You can directly modify the global animations of PopMenu through static properties:
// Set global PopMenu enter animation duration
PopMenu.overrideEnterDuration = 1000;
// Set global PopMenu exit animation duration
PopMenu.overrideExitDuration = 1000;
// Set menu content (List<CharSequence>, String[] or CharSequence[])
.setMenuList(...)
// Close the dialog
.dismiss();
// Set menu height
.setHeight(int);
// Set menu width
.setWidth(int);
// Set menu text style
.setMenuTextInfo(TextInfo);
// Allow display beyond the screen
.setOffScreen(boolean);
// Overlay (attach) on the bound View
.setOverlayBaseView(boolean)
// Get the instantiated dialog object, you can use this method for deeper customization of the Dialog's functionality
.getDialogImpl()
// Get custom layout instance
.getCustomView()
// Set dialog corner radius (will clip the content display)
.setRadius(float px)
// Check if it is currently showing
.isShow()
TextInfo is used to store basic text style settings, containing a series of properties and their corresponding get/set methods, explained as follows:
Property | Explanation | Default Value |
---|---|---|
fontSize | Font size, use default style when value is -1, unit: dp | -1 |
gravity | Alignment, use default style when value is -1, values like Gravity.CENTER can be used |
-1 |
fontColor | Text color, use default style when value is 1, values can be obtained with Color.rgb(r,g,b) | 1 |
bold | Bold style | false |
Please note, fontColor is a ColorInt value, you can set a HEX color with Color.parseColor("#4D000000")
, or set a color resource with getResources().getColor(R.color.black30)
. Do not directly pass in a resource ID as it may be ineffective.
If your App incorporates multiple themes and you need a dialog to display in a specific non-global theme style in certain scenarios, you can use .build()
to construct the dialog. Then, apply .setStyle(style)
to specify the theme style, and finally execute .show()
to display the dialog. For example:
PopMenu.build()
// or directly use .build(IOSStyle.style())
.setStyle(IOSStyle.style())
.setMenuList(new String[]{"Menu 1", "Menu 2", "Menu 3"})
.show();