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

# Annotation toolbar customization in Android

Learn how to customize and create a custom AnnotationToolbarComponent for convenient annotation creation in your app. Switch between tools easily and hide specific buttons with ToolManager. Optimize y

[`AnnotationToolbarComponent`](https://sdk.apryse.com/api/android/javadoc/reference/com/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://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%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:

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

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

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

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

{% tabs %}
{% 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 AnnotationToolbarComponent(
        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="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/android/javadoc/reference/com/pdftron/pdf/widget/toolbar/component/AnnotationToolbarComponent.html) and [`AnnotationToolbarComponent.hide(boolean)`](https://sdk.apryse.com/api/android/javadoc/reference/com/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/android/javadoc/reference/com/pdftron/pdf/tools/ToolManager.html). This will also hide the tool in the quick menu. For example:

{% tabs %}
{% 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://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-1c1d424e10816c07c7d16af63466592d9b1ce628%2F9a81d8b6f7a1d3372ad64c240e5f0679d4bb347b-24x24.svg?alt=media) | `RECT_CREATE`           |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-e4e33c56f007bc51eea6f744a88ad3488af0eb20%2F120cca1bbbafe69fc2e401936ac768add70b22e6-24x24.svg?alt=media) | `OVAL_CREATE`           |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-3d23e958c364b9c9f7f1eabd551344c5eebde365%2Fb12c8a3e27c54bca226b872f8a905d50d86fb798-24x24.svg?alt=media) | `POLYLINE_CREATE`       |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-3a3ce70ad76520c3f421a1823fab081cc658767f%2Fdc5595673a06087adf0089101060106dd99e9290-24x24.svg?alt=media) | `POLYGON_CREATE`        |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-334579f3c43fe4c545387e019893011b3543e6ae%2Feffac6045aca57928ccb5d3aa2cbc87c61316c9c-24x24.svg?alt=media) | `CLOUD_CREATE`          |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-c20d84c853c60f5dc3db82d2f9ee9b51b4f1e99e%2F51edc969eb91d7192e88e5198d636e479e6dcd14-24x24.svg?alt=media) | `LINE_CREATE`           |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-b4d6f026887a84ea30eff8a00943d189f15bc755%2F033443eedda0e4c596e40786020ca58eb81b8626-24x24.svg?alt=media) | `ARROW_CREATE`          |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-202c4fe4f6690a01f41b1aca77c1ddfc7279e49f%2F0a8369e09eda863761e52861bb52721639cfc1bb-24x24.svg?alt=media) | `RULER_CREATE`          |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-c48ff2b5f71708c110cf9a6799efeecefce4354a%2Fb409a23d049a72d5e0776e6ab7a10fe8f4492b32-24x24.svg?alt=media) | `TEXT_CREATE`           |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-b44c232f2e5c4246620c7b9f512213841d096dbf%2F3d18c76eaf50b917c44c5c8e2d4b2c68f8292001-24x24.svg?alt=media) | `CALLOUT_CREATE`        |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-205aecff8c218d172d65434d865a725d5cdd6eb3%2Fcb2e68870a99880261708f138ab6f14128a55201-24x24.svg?alt=media) | `TEXT_ANNOT_CREATE`     |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-f58c360e5a9355c2d9dd95423ba99bd1d04a6ea8%2F356d8532995c5a5a99eecfa9c001c3286f04ea3e-24x24.svg?alt=media) | `INK_CREATE`            |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-e37e4d0227b7c88f5f9c9c24d5926d8a32c7254a%2Fa2b066cf9b51ce6b8122da4d2ef2926a37e69730-24x24.svg?alt=media) | `INK_ERASER`            |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-04441d8f60bc2d65f41ce1e640b78d6752237d8e%2F644d3fc352883a49adeb23b4de481c31cd0bdbb6-24x24.svg?alt=media) | `SIGNATURE`             |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-33bc19967a7d3c3bee985d081ef913ce6b9a1f26%2Fb3e2b5da8d91ac87b9f87c5c22178ac37604baee-24x24.svg?alt=media) | `STAMPER`               |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-c61c9dfe355ba997f44e9fdc0ee44b9999f0205f%2F5917d9a05bc01aff851a3d7a3e5f1c04a7ddefbe-24x24.svg?alt=media) | `RUBBER_STAMPER`        |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-dc6a65856fd54c58669ad9d9b3b966b32fae361b%2Ff38eb9045d6707537a9d2925c468ff7c938ac620-24x24.svg?alt=media) | `FREE_HIGHLIGHTER`      |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-f462694c891b12cef763bcb6d49db217b6b321a3%2F71c5db15fe224b8325ee73b398cd6bd6165e9a60-24x24.svg?alt=media) | `TEXT_HIGHLIGHT`        |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-d968a765a85a035edf5d4f705dc22588b118c3eb%2Fd1ccdcff4e8b99619fcaa5ef9167f7835010f44d-24x24.svg?alt=media) | `TEXT_UNDERLINE`        |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-b793112c3bc5fe4eef238675817cc2b0a8658cec%2Fc73e8eeb4b36e518c805324b38e19dea48d5eeb7-24x24.svg?alt=media) | `TEXT_SQUIGGLY`         |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-103cd0f0eaea65fbea74ff0188fc6ef9ab1dab62%2F258f7041e187cdf49d5297b5fd77deaae5368f7f-24x24.svg?alt=media) | `TEXT_STRIKEOUT`        |
| ![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%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/android/javadoc/reference/com/pdftron/pdf/widget/toolbar/component/AnnotationToolbarComponent.AnnotationButtonClickListener.html) to be notified of annotation toolbar button click events.

{% tabs %}
{% tab title="Java" %}
{% 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 %}
{% endtab %}
{% endtabs %}

## 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 ](/android/ui-customization/custom-theme-a.md).


---

# 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/android/annotation/annotation-toolbar-a.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.
