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?) {

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 { ==}
        if (highlighterItem != null) {

        // Replace the menu items.

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