> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/xamarin/ui-customization/customize-quick-menu.md).

# Customize Quick Menu

Discover the best tips and examples for writing a compelling meta description. Learn how to improve your website's SEO and increase click-through rates. The Apryse Xamarin SDK streamlines secure, serv

You can use a customize the quick menu with a custom list of tools.

## Customize quick menu in Xamarin.Android

{% hint style="info" %}
This tutorial only applies to Xamarin.Android.
{% endhint %}

It is possible to customize the quick menu by [overriding the default menu resource XML files](#override-menu-resources), or by [creating your own](#create-your-own-quick-menu).

## 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 using the `ShowQuickMenu` event and adding a link button. Menu entries can be moved around and removed as well.

1. Add a menu entry to the `ids.xml` in `Resources/values` to identify it:

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<resources>
    ...

    <item name="qm_custom_link" type="id" />
    
    ...
</resources>
```

{% endcode %}
{% endtab %}
{% endtabs %}

1. Create event handler for the `ShowQuickMenu` event, and add the code below to create a new `QuickMenuItem` and specify the order you would like for it to show:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
mPdfViewCtrlTabHostFragment.CurrentPdfViewCtrlFragment.ShowQuickMenu += (sender, e) =>
{
    if (e.Annot != null && e.Annot.Type == (int) Annot.Type.e_Square)
    {
        QuickMenuItem item = new QuickMenuItem(this, Resource.Id.qm_custom_link,
            QuickMenuItem.FirstRowMenu);
        item.SetTitle("Custom Link");
        item.SetIcon(Resource.Drawable.ic_link_black_24dp);
        item.SetOrder(3);
        List<QuickMenuItem> items = new List<QuickMenuItem>(1);
        items.Add(item);
        e.Quickmenu.AddMenuEntries(items);
    }
    e.Handled = false;
};
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
    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);
    }
```

{% endcode %}
{% endtab %}
{% endtabs %}

The quick menu for the square tool will now have a link item at the 3rd (0 index) position like this:

<figure><img src="https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-cea8d4a2b5174da54a1ee13fed9c023cd035ccc7%2F0c724eb36bf4163d51b1b6841828f03d251bdbf9-930x789.png?alt=media" alt="" width="333"><figcaption></figcaption></figure>

Quickmenu items can be removed by calling the `removeMenuEntries` method in the `QuickMenu` class:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
mPdfViewCtrlTabHostFragment.CurrentPdfViewCtrlFragment.ShowQuickMenu += (sender, e) =>
{
    if (e.Annot != null && e.Annot.Type == (int) Annot.Type.e_Square)
    {
        QuickMenuItem item = new QuickMenuItem(this, Resource.Id.qm_custom_link,
            QuickMenuItem.FirstRowMenu);
        List<QuickMenuItem> items = new List<QuickMenuItem>(1);
        items.Add(item);
        e.Quickmenu.RemoveMenuEntries(items);
    }
    e.Handled = false;
};
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
if (annot.getType() == Annot.e_Square) {
    QuickMenuItem item = new QuickMenuItem(MainActivity.this, R.id.qm_custom_link, 
        QuickMenuItem.FIRST_ROW_MENU);
    ArrayList<QuickMenuItem> items = new ArrayList<>(1);
    items.add(item);
    quickMenu.removeMenuEntries(items);
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### 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.

1. Create a menu resource XML file called `pan.xml` in your project's `Resources/menu` folder. This `pan.xml` file will automatically be used instead of the default one in the tools package. To override other quick menus, refer to the [table below](#quick-menu-resources) to determine the name of the menu resource file.
2. Add two items to you menu in `pan.xml` with the `id` attributes `@+id/qm_free_text` and `@+id/qm_floating_sig`:Here we use the ids `@+id/qm_free_text` and `@+id/qm_floating_sig` to override the `Free Text` and `Signature` menu items.Now, when you long-press on a blank space, you will see:

```xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/qm_free_text" android:title="@string/tools_qm_free_text" android:icon="@drawable/ic_annotation_freetext_black_24dp" />
    <item android:id="@+id/qm_floating_sig" android:title="@string/tools_qm_signature" android:icon="@drawable/ic_annotation_signature_black_24dp" />
</menu>
```

{% hint style="info" %}
You can also create your own menu items by providing a unique id, or by overriding our other menu items using the menu ids defined in the tools package. You can learn more about [handling custom menu item click events](#click-events).
{% endhint %}

<figure><img src="https://2401778818-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvUuF7dc8Zt8paqr2K3iP%2Fuploads%2Fgit-blob-8e31fdfc249cff65ba6cedcdc9410f2e1d68af10%2F4285295ec2f0d856fcb1a93e9376eba6368cafb6-363x231.png?alt=media" alt="" height="231"><figcaption></figcaption></figure>

#### 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`](/xamarin/ui-customization/ui-customization/custom-tool.md) as well as in your application logic directly. By the end of this tutorial, you will be able to create your own quick menu.

1. First, add a menu resource XML file in your project's `Resources/menu` folder. For example, let's create a file called `custom.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. |

1. Add the following to `custom.xml`:

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:id="@id/qm_first_row_group">
        <item android:id="@+id/rectangle"
            android:title="@string/tools_qm_rectangle"
            android:icon="@drawable/ic_annotation_square_black_24dp" />
    </group>
    <group android:id="@id/qm_second_row_group">
        <item android:id="@+id/line"
            android:title="@string/annot_line"
            android:icon="@drawable/ic_annotation_line_black_24dp"/>
        <item android:id="@+id/free_text"
            android:title="@string/tools_qm_free_text"
            android:icon="@drawable/ic_annotation_freetext_black_24dp"/>
    </group>
    <group android:id="@id/qm_overflow_row_group">
        <item android:id="@+id/floating_sig"
            android:title="@string/tools_qm_signature"/>
        <item android:id="@+id/link"
            android:title="@string/annot_link"/>
    </group>
</menu>
```

{% endcode %}
{% endtab %}
{% endtabs %}

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:

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:id="@id/qm_first_row_group">
        <item android:id="@+id/rectangle"
            android:title="@string/tools_qm_rectangle"
            android:icon="@drawable/ic_annotation_square_black_24dp" >
            <!-- Sub menu added to Rectangle menu item -->
            <menu>
                <group android:id="@id/qm_first_row_group">
                    <item android:id="@+id/oval"
                        android:title="@string/annot_circle"/>
                </group>
            </menu>
        </item>
    </group>
    <group android:id="@id/qm_second_row_group">
        <item android:id="@+id/line"
            android:title="@string/annot_line"
            android:icon="@drawable/ic_annotation_line_black_24dp"/>
        <item android:id="@+id/free_text"
            android:title="@string/annot_free_text"
            android:icon="@drawable/ic_annotation_freetext_black_24dp"/>
    </group>
    <group android:id="@id/qm_overflow_row_group">
        <item android:id="@+id/floating_sig"
            android:title="@string/tools_qm_signature"/>
        <item android:id="@+id/link"
            android:title="@string/annot_link"/>
    </group>
</menu>
```

{% endcode %}
{% endtab %}
{% endtabs %}

For more information on defining an XML menu resource, see [Defining a Menu in XML](https://developer.android.com/guide/topics/ui/menus#xml).

1. After adding the menu resource XML, initialize `QuickMenu` as follows:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
void InitQuickMenu(PDFViewCtrl pdfViewCtrl)
{
    var quickMenu = new QuickMenu(pdfViewCtrl);
    quickMenu.InitMenuEntries(Resource.menu.custom);
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
    private void initQuickMenu(PDFViewCtrl pdfViewCtrl) {
        QuickMenu quickMenu = new QuickMenu(pdfViewCtrl);
        quickMenu.initMenuEntries(R.menu.custom);
    }
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
    private void initQuickMenu(PDFViewCtrl pdfViewCtrl) {
        QuickMenu quickMenu = new QuickMenu(pdfViewCtrl);
        quickMenu.initMenuEntries(R.menu.custom);
    }
```

{% endcode %}
{% endtab %}
{% endtabs %}

Alternatively, if you want to customize menu items manually you can call [QuickMenu.Inflate](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.QuickMenu.html#pdftron_PDF_Tools_QuickMenu_Inflate_System_Int32_) to prevent auto-initialization. Then after customizing the items, call [QuickMenu.initMenuEntries](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.QuickMenu.html#pdftron_PDF_Tools_QuickMenu_InitMenuEntries) to apply your changes:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
    void InitQuickMenu(PDFViewCtrl pdfViewCtrl) {
        var quickMenu = new QuickMenu(pdfViewCtrl);
        quickMenu.Inflate(Resource.Menu.custom);
        var quickMenuItem = (QuickMenuItem) quickMenu.Menu.FindItem(Resource.Id.rectangle);
        // Customize my quick menu item
        quickMenuItem.SetIcon(Resource.Drawable.my_custom_icon);
        quickMenuItem.SetTitle(Resource.String.my_custom_title);
        // Initialize quick menu
        quickMenu.InitMenuEntries();
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
    private void initQuickMenu(PDFViewCtrl pdfViewCtrl) {
        QuickMenu quickMenu = new QuickMenu(pdfViewCtrl);
        quickMenu.inflate(R.menu.custom);
        QuickMenuItem quickMenuItem = (QuickMenuItem) quickMenu.getMenu().findItem(R.id.rectangle);
        // Customize my quick menu item
        quickMenuItem.setIcon(R.drawable.my_custom_icon);
        quickMenuItem.setTitle(R.string.my_custom_title);
        // Initialize quick menu
        quickMenu.initMenuEntries();
    }
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
    private fun initQuickMenu(pdfViewCtrl: PDFViewCtrl) {
        val quickMenu = QuickMenu(pdfViewCtrl)
        quickMenu.inflate(R.menu.custom)
        val quickMenuItem = quickMenu.menu.findItem(R.id.rectangle) as QuickMenuItem
        // Customize my quick menu item
        quickMenuItem.setIcon(R.drawable.my_custom_icon)
        quickMenuItem.setTitle(R.string.my_custom_title)
        // Initialize quick menu
        quickMenu.initMenuEntries()
    }
```

{% endcode %}
{% endtab %}
{% endtabs %}

1. 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)](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.QuickMenu.html#pdftron_PDF_Tools_QuickMenu_SetAnchor_Android_Views_View_)

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
    private void ShowQuickMenu(QuickMenu quickMenu, View view) {
        quickMenu.SetAnchor(view);
        quickMenu.Show();
    }
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
    private void showQuickMenu(QuickMenu quickMenu, View view) {
        quickMenu.setAnchor(view);
        quickMenu.show();
    }
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
    private fun showQuickMenu(quickMenu: QuickMenu, view: View) {
        quickMenu.setAnchor(view)
        quickMenu.show()
    }
```

{% endcode %}
{% endtab %}
{% endtabs %}

The quick menu will automatically adjust its position to either the top or bottom of the anchor view, depending on the space available:

<figure><img src="https://2401778818-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvUuF7dc8Zt8paqr2K3iP%2Fuploads%2Fgit-blob-4d0221763e41abe22009fa04ee5b42898be9dde2%2F39b2791ce1eef86bc21725695eb50746a58561a1-200x400.png?alt=media" alt="quick-menu-layout image" width="200"><figcaption></figcaption></figure>

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

Without sub menu:

<figure><img src="https://2401778818-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvUuF7dc8Zt8paqr2K3iP%2Fuploads%2Fgit-blob-8a5a7b11051d12c63569a6cc2f6db9eca36485f1%2F6cdf576ed5556c56232f28dab2b2712fe36c4a4e-248x267.gif?alt=media" alt="quick menu without sub menu image" width="248"><figcaption></figcaption></figure>

With sub menu:

<figure><img src="https://2401778818-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvUuF7dc8Zt8paqr2K3iP%2Fuploads%2Fgit-blob-6a6986c2f6087075d6f264f9dc71566c3cfee5d8%2Fce9de57d692c843348c9b7cff815cbce4009e9c7-292x241.gif?alt=media" alt="quick menu with sub menu image" width="248"><figcaption></figcaption></figure>

### 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 this guide](/xamarin/ui-customization/quick-menu.md) or by implementing [`DismissEvent`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.QuickMenu.html#pdftron_PDF_Tools_QuickMenu_DismissEvent):

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
quickMenu.DismissEvent += (sender, e) =>
{
    // Get selected quick menu item
    var selectedMenuItem = quickMenu.SelectedMenuItem;
    // Provide functionality depending on the menu item selected
    // ...
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
quickMenu.setOnDismissListener(new QuickMenu.OnDismissListener() {
    @Override
    public void onDismiss() {
        // Get selected quick menu item
        QuickMenuItem selectedMenuItem = quickMenu.getSelectedMenuItem();
        // Provide functionality depending on the menu item selected
        // ...
    }
});
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
quickMenu.setOnDismissListener {
    // Get selected quick menu item
    val selectedMenuItem = quickMenu.selectedMenuItem
    // Provide functionality depending on the menu item selected
    // ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/xamarin/ui-customization/customize-quick-menu.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
