How to Remove a Button from Toolbars

You can edit PSPDFKit’s toolbars before they’re displayed onscreen. This example shows how to remove the ink highlighter button from the annotation creation toolbar:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setOnContextualToolbarLifecycleListener(this)
}

override fun onPrepareContextualToolbar(toolbar: ContextualToolbar<*>) {
    if (toolbar is AnnotationCreationToolbar) {
        // Get the existing menu items so you can modify them.
        val menuItems = toolbar.menuItems

        // Find and remove the ink highlighter button from the toolbar.
        val highlighterItem = menuItems.find { it.id ==  R.id.pspdf__annotation_creation_toolbar_item_ink_highlighter}
        if (highlighterItem != null) {
            menuItems.remove(highlighterItem)
        }

        // Replace the menu items.
        toolbar.setMenuItems(menuItems)
    }
}

override fun onDisplayContextualToolbar(toolbar: ContextualToolbar<*>) {}
override fun onRemoveContextualToolbar(toolbar: ContextualToolbar<*>) {}