Customize quick menu in Android
Customize quick menu in Android
It is possible to customize the quick menu by overriding the default menu resource XML files, or by creating your own.
Add/remove item to the quick menu
It is possible to programmatically modify the quick menu by calling methods to add and remove items.
The following example will customize the quick menu for the Square tool by overriding the onShowQuickMenu function and adding a link button. Menu entries can be moved around and removed as well.
Add a menu entry to the
ids.xmlinResources/valuesto identify it:
<resources>
...
<item name="qm_custom_link" type="id" />
...
</resources>Create event handler for the
onShowQuickMenuevent, and add the code below to create a newQuickMenuItemand specify the order you would like for it to show:
if (annot.getType() == Annot.e_Square) {
QuickMenuItem item = new QuickMenuItem(MainActivity.this, R.id.qm_custom_link,
QuickMenuItem.FIRST_ROW_MENU);
item.setTitle(R.string.qm_custom_link);
item.setIcon(R.drawable.ic_link_black_24dp);
item.setOrder(3);
ArrayList<QuickMenuItem> items = new ArrayList<>(1);
items.add(item);
quickMenu.addMenuEntries(items);
}The quick menu for the square tool will now have a link item at the 3rd (0 index) position like this:

Quickmenu items can be removed by calling the removeMenuEntries method in the QuickMenu class:
Override menu resources
In this tutorial you will customize the quick menu for the Pan tool by overriding the default menu resource XML file in the Apryse SDK.
Create a menu resource XML file called
pan.xmlin your project'sResources/menufolder. Thispan.xmlfile will automatically be used instead of the default one in the tools package. To override other quick menus, refer to the table below to determine the name of the menu resource file.Add two items to you menu in
pan.xmlwith theidattributes@+id/qm_free_textand@+id/qm_floating_sig:Here we use the ids@+id/qm_free_textand@+id/qm_floating_sigto override theFree TextandSignaturemenu items.Now, when you long-press on a blank space, you will see:

Quick menu resources
pan
Pan
Long press on blank space
text_select
TextSelect
Long press on text
annot_simple_shape
AnnotEdit
Single tap on Square, Circle, Line, Polygon, Polyline, Text
annot_free_text
AnnotEdit
Single tap on FreeText
annot_link
AnnotEdit
Single tap on Link
annot_signature
AnnotEdit
Single tap on signature (type: Annot.e_Stamp and custom field: Signature.SIGNATURE_ANNOTATION_ID)
annot_stamper
AnnotEdit
Single tap on Stamp(type: Annot.e_Stamp)
annot_file_attachment
AnnotEdit
Single tap on FileAttachment
annot_free_hand
AnnotEdit
Single tap on Ink
annot_general
AnnotEdit
Single tap on all other annotation types
annot_edit_text_markup
AnnotEditTextMarkup
Single tap on TextMarkup annotations
type
AnnotEditTextMarkup
Click quick menu item with id R.id.type
sig_field_image
DigitalSignature
Single tap on digital image signature
annot_edit_thickness
DigitalSignature
Click quick menu item with id R.id.thickness
sig_field_paths
DigitalSignature
Single tap on digital signature, or click on items in quick menu R.menu.annot_edit_thickness
Create your own quick menu
You can use quick menus in a ToolManager as well as in your application logic directly. By the end of this tutorial, you will be able to create your own quick menu.
First, add a menu resource XML file in your project's
res/menufolder. For example, let's create a file calledcustom.xml.
By default, all menu items are placed in the first row of the quick menu. If you want to specify the location of a menu item, enclose the item inside a group with a group id from this list:
Group id
Location in quick menu
@id/qm_first_row_group
First row group id: all menu items inside this group will be displayed in the first row of the quick menu.
@id/qm_second_row_group
Second row group id: all menu items inside this group will be displayed in the second row of the quick menu.
@id/qm_overflow_row_group
Overflow list group id: all menu items inside this group will be displayed in the overflow menu list of the quick menu.
Add the following to
custom.xml:
You can also add a sub menu by specifiying it in the menu resource XML. For example, we can add an Oval menu item as a submenu under the Rectangle menu item by changing custom.xml to:
For more information on defining an XML menu resource, see Defining a Menu in XML.
After adding the menu resource XML, initialize
QuickMenuas follows:
Alternatively, if you want to customize menu items manually you can call QuickMenu.inflate to prevent auto-initialization. Then after customizing the items, call QuickMenu.initMenuEntries to apply your changes:
When you want to show the quick menu, set an anchor view that defines where the quick menu should appear by calling
QuickMenu.SetAnchor(View), then callQuickMenu.Show()
The quick menu will automatically adjust its position to either the top or bottom of the anchor view, depending on the space available:

At this point, you should see the following when the quick menu is shown:
Without sub menu:

With sub menu:

Click events
Click events from your custom items will not be automatically handled by the Apryse SDK if the menu item id does not match any of the default ids defined in the tools package (located in the PDFViewCtrlTools\res\menu\ids.xml file). You will have to handle these events as described in the Quick Menu guide or by implementing onDismiss():
Quick menu style
Icon style
You can call the following methods to customize the quick menu item icons programmatically before they are initialized:
Method call
Description
Set the menu item icon
Set the icon color
Set the icon opacity
Example
You can also customize the icon using the android:icon attribute in your menu resource XML file. Additionally if your Android app supports minimum API level 26, you can set the icon tint color and tint mode by setting the android:iconTint and android:iconTintMode attributes.
Example
Button style
QuickMenu uses R.style.QuickMenuButton for the buttons style. You can change the style by overriding it in your res/value/style.xml file.
If you want to change the button style the after quick menu is displayed, you can find the button by calling QuickMenu.findMenuItem(QuickMenuItem). Once the button is found, how you set its style programmatically depends on whether it is an ImageButton or a Button.
Example
Background
The quick menu background uses drawable/quickmenu_bg_rect.xml for API 21 and above and drawable/quickmenu_bg_rect_old_api for API under 21. You can change the background by overriding these drawable files.
Divider
There is a hairline divider between the first and second row of the quick menu. If both rows exist, the divider is VISIBLE by default. You can hide this hairline divider by calling QuickMenu.setDividerVisibility(View.INVISIBLE)
Last updated
Was this helpful?