When an annotation is selected, Nutrient Android SDK shows a popup toolbar directly next to the annotation on the page. The popup toolbar provides contextual actions for the selected annotation.

To learn more about customizing the style of toolbars, refer to our information on toolbar styling.

Selecting annotations programmatically

When a user taps an annotation, the activity will enter annotation mode for the selected annotation.

In your code, you can select annotations programmatically by calling PdfFragment#setSelectedAnnotation:

pdfFragment.setSelectedAnnotation(annotation)

To leave the annotation mode (switching back to the normal viewing mode), you can call PdfFragment#exitCurrentlyActiveMode:

// Leaves a previously launched annotation mode.
pdfFragment.exitCurrentlyActiveMode()

PdfFragment#exitCurrentlyActiveMode can also be used to leave other special modes — for example, annotation creation or text selection.

Mode listeners

If you need more control over annotation mode, you can register an OnAnnotatingModeChangeListener on the fragment. After entering annotation mode, the listener will be called, giving you access to the AnnotatingController. The controller object gives you access to all annotation mode actions — saving, deleting, toggling the inspector, selecting annotations, etc.

The popup toolbar offers several actions for performing operations on a selected annotation:

ActionDescription
CopyCopies the selected annotation to the clipboard.
DeleteDeletes the selected annotation.
InspectorOpens the annotation inspector (color/style picker).
NoteOpens the annotation note editor.
ShareShares the annotation contents.
Play/RecordPlays or records sound annotations.
Group/UngroupGroups or ungroups selected annotations.

Customizing the popup toolbar

You can customize the annotation popup toolbar before it’s displayed by registering an OnPreparePopupToolbarListener on the fragment. Override onPrepareAnnotationPopupToolbar to modify the toolbar items:

pdfFragment.setOnPreparePopupToolbarListener(object : OnPreparePopupToolbarListener {
override fun onPrepareAnnotationPopupToolbar(toolbar: AnnotationPopupToolbar) {
// Access the currently selected annotations.
val annotations = toolbar.annotations
// Remove or add menu items as needed.
val menuItems = toolbar.menuItems.toMutableList()
menuItems.removeAll { it.id == R.id.pspdf__annotation_popup_toolbar_item_share }
toolbar.menuItems = menuItems
}
})

The OnPreparePopupToolbarListener also provides callbacks for other popup toolbar types. See the popup toolbar customization section in the 11.3 release notes for the full list.

Annotation inspector

The annotation inspector is a Nutrient UI component that allows editing of annotation properties. Once you open it, it’ll slide up from the bottom of the screen. To learn more about the annotation inspector, refer to the annotation inspector guide.