Annotation editing on Android
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)getPdfFragment().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()// Leaves a previously launched annotation mode.getPdfFragment().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.
Popup toolbar actions
The popup toolbar offers several actions for performing operations on a selected annotation:
| Action | Description |
|---|---|
| Copy | Copies the selected annotation to the clipboard. |
| Delete | Deletes the selected annotation. |
| Inspector | Opens the annotation inspector (color/style picker). |
| Note | Opens the annotation note editor. |
| Share | Shares the annotation contents. |
| Play/Record | Plays or records sound annotations. |
| Group/Ungroup | Groups 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 }})getPdfFragment().setOnPreparePopupToolbarListener(new OnPreparePopupToolbarListener() { @Override public void onPrepareAnnotationPopupToolbar(@NonNull AnnotationPopupToolbar toolbar) { // Access the currently selected annotations. List<Annotation> annotations = toolbar.getAnnotations();
// Remove or add menu items as needed. List<PopupToolbarMenuItem> menuItems = new ArrayList<>(toolbar.getMenuItems()); menuItems.removeIf(item -> item.getId() == R.id.pspdf__annotation_popup_toolbar_item_share); toolbar.setMenuItems(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.