> 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/annotation/annotation-toolbar.md).

# Annotation Toolbar

Customize annotation toolbar for Xamarin.Android viewer to conveniently create and switch between annotation tools. Learn how to customize, show/hide toolbar items, and disable specific tools for a ta

You can customize the annotation toolbars for the document viewers.

{% tabs %}
{% tab title="Android" %}

## Customize annotation toolbar for Xamarin.Android viewer

{% hint style="info" %}
**This tutorial only applies to Xamarin.Android. See Xamarin.iOS equivalent here .**
{% endhint %}

[`AnnotationToolbarComponent`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Widget.Toolbar.Component.AnnotationToolbarComponent.html) is a class that contains the logic and views that make up the annotation toolbar. The annotation toolbar can be customized to contain a number of annotation creation tools button as well as any custom button. With the annotation toolbar, users are able to conveniently create annotations and switch between different tools.

The buttons on the annotation toolbar are contained in two groups: the scrollable region (left) and the sticky region (right). The scrollable region can contain any number of buttons and scrolling is used to access buttons that are off-screen. Buttons in the sticky region will always show on the screen and will not be scrollable.

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-fad02f6c7875e7832584f9f7b75b312fb19db616%2Faed4c7de996b54bb1e54ee752c13d39d4aa3775c-800x413.gif?alt=media)

{% hint style="info" %}
**To learn more about each icon, see the icon cheat sheet .**
{% endhint %}

## Create a custom annotation toolbar

The annotation toolbar allows users to easily switch tools when adding annotations to a document. To add an annotation toolbar to your app, first define some layout groups in your app that will contain the annotation toolbar:

{% code lineNumbers="true" %}

```xml
<FrameLayout android:id="@+id/annotation_toolbar_container" android:layout_width="match_parent" android:layout_height="wrap_content"/>
```

{% endcode %}

Then in your activity, setup your `AnnotationToolbarComponent` with [`ToolManager`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.ToolManager.html) and attach the required ViewModel classes:

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

```csharp
AnnotationToolbarComponent annotationToolbarComponent;
// ...
private void SetupAnnotationToolbar(ToolManager toolManager)
{
    // First find our container view group
    var mToolbarContainer = FindViewById(Resource.Id.annotation_toolbar_container);

    // Then setup ToolManager and related ViewModels with AnnotationToolbarComponent
    // Remember to initialize your ToolManager before calling below
    var vmProvider = ViewModelProviders.Of(this);
    var toolManagerVm = (ToolManagerViewModel)vmProvider.Get(Java.Lang.Class.FromType(typeof(ToolManagerViewModel)));
    toolManagerVm.ToolManager = toolManager;
    var presetVm = (PresetBarViewModel)vmProvider.Get(Java.Lang.Class.FromType(typeof(PresetBarViewModel)));
    var annotToolbarVm = (AnnotationToolbarViewModel)vmProvider.Get(Java.Lang.Class.FromType(typeof(AnnotationToolbarViewModel)));

    // Create our UI component for the annotation toolbar
    annotationToolbarComponent = new AnnotationToolbarComponent(this, annotToolbarVm, presetVm, toolManagerVm, mToolbarContainer);
}
```

{% endcode %}
{% endtab %}

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

```java
private AnnotationToolbarComponent mAnnotationToolbarComponent;
...
public void setupAnnotationToolbar(ToolManager toolManager) {
    // First find our container view group
    FrameLayout mToolbarContainer = findViewById(R.id.annotation_toolbar_container);
    
	// Then setup ToolManager and related ViewModels with AnnotationToolbarComponent 
    // Remember to initialize your ToolManager before calling below
    ViewModelProvider vmProvider = ViewModelProviders.of(this);
    ToolManagerViewModel toolManagerVm = vmProvider.get(ToolManagerViewModel.class);
    toolManagerVm.setToolManager(toolManager);
    PresetBarViewModel presetVm = vmProvider.get(PresetBarViewModel.class);
    AnnotationToolbarViewModel annotToolbarVm = vmProvider.get(AnnotationToolbarViewModel.class);
    // Create our UI component for the annotation toolbar
    mAnnotationToolbarComponent = new AnnotaetionToolbarComponent(
        this,
        annotToolbarVm,
        presetVm,
        toolManagerVm,
        mToolbarContainer
    );
}
```

{% endcode %}
{% endtab %}

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

```kotlin
lateinit var mAnnotationToolbarComponent: AnnotationToolbarComponent
...
fun setupAnnotationToolbar(toolManager: ToolManager?) {
    // First find our container view group
    val mToolbarContainer: FrameLayout = findViewById(R.id.annotation_toolbar_container)
    // Then setup ToolManager and related ViewModels with AnnotationToolbarComponent
    // Remember to initialize your ToolManager before calling below
    val vmProvider: ViewModelProvider = ViewModelProviders.of(this)
    val toolManagerVm: ToolManagerViewModel = vmProvider.get(ToolManagerViewModel::class.java)
    toolManagerVm.toolManager = toolManager
    val presetVm: PresetBarViewModel = vmProvider.get(PresetBarViewModel::class.java)
    val annotToolbarVm: AnnotationToolbarViewModel = vmProvider.get(AnnotationToolbarViewModel::class.java)
    // Create our UI component for the annotation toolbar
    mAnnotationToolbarComponent = AnnotationToolbarComponent(
            this,
            annotToolbarVm,
            presetVm,
            toolManagerVm,
            mToolbarContainer
    )
}
```

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

Finally, you can customize the annotation toolbar by either using one of our default toolbars or creating a custom toolbar from scratch.

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

```csharp
// Use a default toolbar
annotationToolbarComponent.InflateWithBuilder(DefaultToolbars.DefaultAnnotateToolbar);

// Or create a custom toolbar from scratch
annotationToolbarComponent.InflateWithBuilder(
    AnnotationToolbarBuilder.WithTag("Custom Toolbar")
    // Add some pre-defined tools that will be handled internally using ToolManager
    .AddToolButton(ToolbarButtonType.Square, 100)
    .AddToolButton(ToolbarButtonType.Ink, 102)
    .AddToolButton(ToolbarButtonType.FreeHighlight, 103)
    .AddToolButton(ToolbarButtonType.Eraser, 104)
    // We can also add a custom button to handle ourselves, for example here
    // we have added a "favorites" button that contains a star icon
    .AddCustomButton(Resource.String.favorites, Resource.Drawable.annotation_note_icon_star_fill, 105)
    .AddToolStickyButton(ToolbarButtonType.Undo, 106)
    .AddToolStickyButton(ToolbarButtonType.Redo, 107)
    );
```

{% endcode %}
{% endtab %}

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

```java
// Use a default toolbar
mAnnotationToolbarComponent.inflateWithBuilder(
        DefaultToolbars.defaultAnnotateToolbar
);
// Or create a custom toolbar from scratch
mAnnotationToolbarComponent.inflateWithBuilder(
        AnnotationToolbarBuilder.withTag("Custom Toolbar")
                // Add some pre-defined tools that will be handled internally using ToolManager
                .addToolButton(ToolbarButtonType.SQUARE, 100)
                .addToolButton(ToolbarButtonType.INK, 102)
                .addToolButton(ToolbarButtonType.FREE_HIGHLIGHT, 103)
                .addToolButton(ToolbarButtonType.ERASER, 104)
                // We can also add a custom button to handle ourselves, for example here
                // we have added a "favorites" button that contains a star icon
                .addCustomButton(R.string.favorites, R.drawable.annotation_note_icon_star_fill, 105)
                .addToolStickyButton(ToolbarButtonType.UNDO, 106)
                .addToolStickyButton(ToolbarButtonType.REDO, 107)
);
```

{% endcode %}
{% endtab %}

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

```kotlin
mAnnotationToolbarComponent.inflateWithBuilder(
        DefaultToolbars.defaultAnnotateToolbar
);
// Or create a custom toolbar from scratch
mAnnotationToolbarComponent.inflateWithBuilder(
        AnnotationToolbarBuilder.withTag("Custom Toolbar")
                // Add some pre-defined tools that will be handled internally using ToolManager
                .addToolButton(ToolbarButtonType.SQUARE, 100)
                .addToolButton(ToolbarButtonType.INK, 102)
                .addToolButton(ToolbarButtonType.FREE_HIGHLIGHT, 103)
                .addToolButton(ToolbarButtonType.ERASER, 104)
                // We can also add a custom button to handle ourselves, for example here
                // we have added a "favorites" button that contains a star icon
                .addCustomButton(R.string.favorites, R.drawable.annotation_note_icon_star_fill, 105)
                .addToolStickyButton(ToolbarButtonType.UNDO, 106)
                .addToolStickyButton(ToolbarButtonType.REDO, 107)
);
```

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

## Show and hide annotation toolbar

You can show and hide the toolbar by calling [`AnnotationToolbarComponent.show(boolean)`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Widget.Toolbar.Component.AnnotationToolbarComponent.html) and [`AnnotationToolbarComponent.hide(boolean)`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Widget.Toolbar.Component.AnnotationToolbarComponent.html).

## Hide annotation toolbar items

If you have used `ToolManager` to hide certain tools, then the associated tool buttons will also be hidden in the annotation toolbar.

### Hide tool buttons

If there are tools that you would like to remove from the annotation toolbar, you can disable them by calling [`ToolManager.disableToolMode(ToolMode[])`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.ToolManager.html). This will also hide the tool in the quick menu. For example:

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

```csharp
// Disable TextHighlightCreate tool, TextUnderlineCreate tool,
// TextSquigglyCreate tool and TextStrikeoutCreate tool
mToolManager.DisableToolMode(new ToolManager.ToolMode[] {
    ToolManager.ToolMode.TextHighlight,
    ToolManager.ToolMode.TextUnderline,
    ToolManager.ToolMode.TextSquiggly,
    ToolManager.ToolMode.TextStrikeout
});
```

{% endcode %}
{% endtab %}

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

```java
// Disable TextHighlightCreate tool, TextUnderlineCreate tool,
// TextSquigglyCreate tool and TextStrikeoutCreate tool
mToolManager.disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.TEXT_HIGHLIGHT,
    ToolManager.ToolMode.TEXT_UNDERLINE,
    ToolManager.ToolMode.TEXT_SQUIGGLY,
    ToolManager.ToolMode.TEXT_STRIKEOUT}
);
```

{% endcode %}
{% endtab %}

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

```kotlin
// Disable TextHighlightCreate tool, TextUnderlineCreate tool,
// TextSquigglyCreate tool and TextStrikeoutCreate tool
mToolManager!!.disableToolMode(arrayOf(
    ToolManager.ToolMode.TEXT_HIGHLIGHT,
    ToolManager.ToolMode.TEXT_UNDERLINE,
    ToolManager.ToolMode.TEXT_SQUIGGLY,
    ToolManager.ToolMode.TEXT_STRIKEOUT)
)
```

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

For reference, a mapping of `ToolMode` to button icons is shown below:

| Icon                                                                                                                                                                                                                                         | ToolMode                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-1c1d424e10816c07c7d16af63466592d9b1ce628%2F9a81d8b6f7a1d3372ad64c240e5f0679d4bb347b-24x24.svg?alt=media) | `RECT_CREATE`           |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-e4e33c56f007bc51eea6f744a88ad3488af0eb20%2F120cca1bbbafe69fc2e401936ac768add70b22e6-24x24.svg?alt=media) | `OVAL_CREATE`           |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-3d23e958c364b9c9f7f1eabd551344c5eebde365%2Fb12c8a3e27c54bca226b872f8a905d50d86fb798-24x24.svg?alt=media) | `POLYLINE_CREATE`       |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-3a3ce70ad76520c3f421a1823fab081cc658767f%2Fdc5595673a06087adf0089101060106dd99e9290-24x24.svg?alt=media) | `POLYGON_CREATE`        |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-334579f3c43fe4c545387e019893011b3543e6ae%2Feffac6045aca57928ccb5d3aa2cbc87c61316c9c-24x24.svg?alt=media) | `CLOUD_CREATE`          |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-c20d84c853c60f5dc3db82d2f9ee9b51b4f1e99e%2F51edc969eb91d7192e88e5198d636e479e6dcd14-24x24.svg?alt=media) | `LINE_CREATE`           |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-b4d6f026887a84ea30eff8a00943d189f15bc755%2F033443eedda0e4c596e40786020ca58eb81b8626-24x24.svg?alt=media) | `ARROW_CREATE`          |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-202c4fe4f6690a01f41b1aca77c1ddfc7279e49f%2F0a8369e09eda863761e52861bb52721639cfc1bb-24x24.svg?alt=media) | `RULER_CREATE`          |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-c48ff2b5f71708c110cf9a6799efeecefce4354a%2Fb409a23d049a72d5e0776e6ab7a10fe8f4492b32-24x24.svg?alt=media) | `TEXT_CREATE`           |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-b44c232f2e5c4246620c7b9f512213841d096dbf%2F3d18c76eaf50b917c44c5c8e2d4b2c68f8292001-24x24.svg?alt=media) | `CALLOUT_CREATE`        |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-205aecff8c218d172d65434d865a725d5cdd6eb3%2Fcb2e68870a99880261708f138ab6f14128a55201-24x24.svg?alt=media) | `TEXT_ANNOT_CREATE`     |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-f58c360e5a9355c2d9dd95423ba99bd1d04a6ea8%2F356d8532995c5a5a99eecfa9c001c3286f04ea3e-24x24.svg?alt=media) | `INK_CREATE`            |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-e37e4d0227b7c88f5f9c9c24d5926d8a32c7254a%2Fa2b066cf9b51ce6b8122da4d2ef2926a37e69730-24x24.svg?alt=media) | `INK_ERASER`            |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-04441d8f60bc2d65f41ce1e640b78d6752237d8e%2F644d3fc352883a49adeb23b4de481c31cd0bdbb6-24x24.svg?alt=media) | `SIGNATURE`             |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-33bc19967a7d3c3bee985d081ef913ce6b9a1f26%2Fb3e2b5da8d91ac87b9f87c5c22178ac37604baee-24x24.svg?alt=media) | `STAMPER`               |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-c61c9dfe355ba997f44e9fdc0ee44b9999f0205f%2F5917d9a05bc01aff851a3d7a3e5f1c04a7ddefbe-24x24.svg?alt=media) | `RUBBER_STAMPER`        |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-dc6a65856fd54c58669ad9d9b3b966b32fae361b%2Ff38eb9045d6707537a9d2925c468ff7c938ac620-24x24.svg?alt=media) | `FREE_HIGHLIGHTER`      |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-f462694c891b12cef763bcb6d49db217b6b321a3%2F71c5db15fe224b8325ee73b398cd6bd6165e9a60-24x24.svg?alt=media) | `TEXT_HIGHLIGHT`        |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-d968a765a85a035edf5d4f705dc22588b118c3eb%2Fd1ccdcff4e8b99619fcaa5ef9167f7835010f44d-24x24.svg?alt=media) | `TEXT_UNDERLINE`        |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-b793112c3bc5fe4eef238675817cc2b0a8658cec%2Fc73e8eeb4b36e518c805324b38e19dea48d5eeb7-24x24.svg?alt=media) | `TEXT_SQUIGGLY`         |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-103cd0f0eaea65fbea74ff0188fc6ef9ab1dab62%2F258f7041e187cdf49d5297b5fd77deaae5368f7f-24x24.svg?alt=media) | `TEXT_STRIKEOUT`        |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-dd781105b73c1ee31b8ca0f046b906babd519f5f%2F2109952732e26c463f729626218d25d4cf29dca0-24x24.svg?alt=media) | `ANNOT_EDIT_RECT_GROUP` |

## Annotation toolbar listener

You can set an [`AnnotationButtonClickListener`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Widget.Toolbar.Component.AnnotationToolbarComponent.IAnnotationButtonClickListener.html) to be notified of annotation toolbar button click events.

{% code lineNumbers="true" %}

```java
mAnnotationToolbarComponent.addButtonClickListener(new AnnotationToolbarComponent.AnnotationButtonClickListener() {
    @Override
    public boolean onInterceptItemClick(MenuItem menuItem) {
        // We can intercept button click events by implementing this method.
        // Here we can handle our custom "favorites" button by referring to the button's id
        // that was defined above.
        if (menuItem.getItemId() == 105) {
            Toast.makeText(MainActivity.this, "Favorites Pressed", Toast.LENGTH_SHORT).show();
            return true;
        }
        return false;
    }
    @Override
    public void onPreItemClick(MenuItem menuItem) {
    }
    @Override
    public void onPostItemClick(MenuItem menuItem) {
    }
});
```

{% endcode %}

## Edit annotations continuously

For continuous annotation creation, `AnnotationToolbarComponent` will use value set by `PdfViewCtrlSettingsManager.setContinuousAnnotationEdit(Context, boolean)` (by default true). If continuous annotation editing is disabled, then the tool button will be de-selected in the annotation toolbar after creating an annotation.

## Appearance styles

In order to customize the appearance of UI elements in your annotation toolbar, you can define a new style that extends `PTAnnotationToolbarTheme` inside your `res\values\style.xml` file and pass it as an attribute to your viewer's theme named `pt_annotation_toolbar_style`. For more information on customizing the style of UI components, please take a look at our [viewer theme guide ](/xamarin/guides/viewer-components/custom-theme-a.md).
{% endtab %}

{% tab title="iOS" %}

## Customize annotation toolbar for Xamarin.iOS viewer

{% hint style="info" %}
**This tutorial only applies to Xamarin.iOS. See Xamarin.Android equivalent here .**
{% endhint %}

The [`PTAnnotationToolbar`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTAnnotationToolbar.html) class is a [`UIToolbar`](https://developer.apple.com/uikit/uitoolbar/) consisting of various annotation creation tools. With the annotation toolbar, users are able to conveniently create and switch between different tools.

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-ca07ba2bc5f78ee3b353db645048f76fef09138c%2F9c15e4367b2e3531129ca48c5ab0492fccde09a2-2556x1179.png?alt=media)

The annotation toolbar control is part of the Tools library, so make sure you have [added it to your project](/xamarin/annotation/config-annot-tools.md#ios).

{% hint style="info" %}
\*\* Due to space limitations, only a limited number of tools will show up in portrait mode on smaller devices. See the customization section of this guide for more details on how to customize this. \*\*
{% endhint %}

| Scenario                                         | Annotation Toolbar                                                                                                                                                                                                                              |
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Small devices in landscape mode + Tablet devices | ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-2d0f33e6431a2528823efc9022b984e0820b010d%2Fdecc5c514a4f4705a4d845543872a2965f9f5e3c-1466x184.png?alt=media) |
| Small devices in portrait mode                   | ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-1ff159030cfb946fd5d1824d613c98355a128eff%2Feb976be4be65d5be73b0e643fa1526b7135b2104-788x272.png?alt=media)  |

## Show and hide the annotation toolbar

To create and set up an annotation toolbar, initialize an `AnnotationToolbar` instance and add it to your view hierarchy:

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

```csharp
var annotationToolbar = new pdftron.PDF.Controls.PTAnnotationToolbar(mToolManager);
annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
{
    annotationToolbar.Hidden = true;
};
View.AddSubview(annotationToolbar);

// position annotation toolbar
annotationToolbar.TranslatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
    annotationToolbar.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
    annotationToolbar.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
    annotationToolbar.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor)
});

// hide annotation toolbar by default
annotationToolbar.Hidden = true;
```

{% endcode %}
{% endtab %}

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

```swift
let annotationToolbar = PTAnnotationToolbar(toolManager: toolManager)
// Set the current view controller as the annotation toolbar's delegate.
annotationToolbar.delegate = self;
self.view.addSubview(annotationToolbar)
// Position annotation toolbar in superview.
annotationToolbar.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([
    annotationToolbar.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
    annotationToolbar.widthAnchor.constraint(equalTo: self.view.widthAnchor),
    annotationToolbar.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor)
])
// Hide annotation toolbar by default.
annotationToolbar.isHidden = true
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
AnnotationToolbar *annotationToolbar = [[PTAnnotationToolbar alloc] initWithToolManager:toolManager];
// Set the current view controller as the annotation toolbar's delegate.
annotationToolbar.delegate = self;
[self.view addSubview:annotationToolbar];
// Position annotation toolbar in superview.
annotationToolbar.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
   [annotationToolbar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
   [annotationToolbar.widthAnchor constraintEqualToAnchor:self.view.widthAnchor],
   [annotationToolbar.topAnchor constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor],
 ]];
// Hide annotation toolbar by default.
annotationToolbar.hidden = YES;
```

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

To show:

{% code lineNumbers="true" %}

```csharp
// Show the annotation toolbar.
annotationToolbar.Hidden = false;
```

{% endcode %}

## Customization

The [`PTAnnotationToolbar`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTAnnotationToolbar.html) class provides an API for specifying which tools are displayed in the toolbar when there is insufficient space to show them all. This is controlled by the [`PrecedenceArray`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTAnnotationToolbar.html#pdftron_PDF_Controls_PTAnnotationToolbar_PrecedenceArray) property.

## Annotation toolbar delegate

The [`PTAnnotationToolbarDelegate`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTAnnotationToolbarDelegate.html) protocol allows the adopting class (usually the containing view controller, as in [this guide](#customize-annotation-toolbar-for-xamarinios-viewer)) to be notified of annotation toolbar events and control the behavior of the toolbar.

{% code lineNumbers="true" %}

```csharp
annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
{
    annotationToolbar.Hidden = true;
}
```

{% endcode %}

## Edit annotations continuously

By default, the annotation toolbar returns to the pan tool after an annotation is created. If you prefer to stay in the same tool mode after an annotation is created, you should implement the `toolShouldGoBackToPan` method in your `AnnotationToolbarDelegate` adopting class:

{% code lineNumbers="true" %}

```csharp
mAnnotationToolbar.ToolShouldGoBackToPan = (annotationToolbar) =>
{
    return false;
};
```

{% endcode %}

The annotation toolbar's behavior could also be handled within user settings by checking and returning the appropriate settings value in the method above.
{% 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/annotation/annotation-toolbar.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.
