How to remove a button from toolbars?

You can easily edit PSPDFKit’s toolbars before they are displayed. For example, we’ll show 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 we 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<*>) {}