Custom Annotation Click

How can we provide functionality of Annotation on custom annotation click ?
Let us suppose I have create custom annotation using -

AnnotationToolbarBuilder.withTag(“Custom Toolbar”)
.addCustomButton(R.string.custom, R.drawable.custom, 101)

and now I want to perform TEXT_HIGHLIGHT functionality on custom icon click.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:



Using your above example to add a custom button you will need to use the PdfViewCtrlTabHostFragment2.TabHostListener to know when the custom button has been pressed.

In the TabHostListener there is function you can override called onToolbarOptionsItemSelected
Please see the example code below for a highlight tool

    override fun onToolbarOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == 101) { //101 is your custom button id
            val toolManager = mPdfViewCtrlTabHostFragment.currentPdfViewCtrlFragment.toolManager
            val tool = toolManager!!.createTool(ToolManager.ToolMode.TEXT_HIGHLIGHT, null)
            (tool as Tool).isForceSameNextToolMode = true
            toolManager.tool = tool
            return true
        return false

Your AnnotationToolbarBuilder would look something like this

            .withTag("Custom Toolbar")
            .addCustomSelectableButton(R.string.custom, R.drawable.ic_custommode_icon, 101)

We also have sample projects that go into more detail on adding custom tools and buttons. These example can be found here and a more specific example for this scenario can be found here

Best Regards,

Hi Eamon

Thanks for responce.

Could you please give me more favour.

Can we replace our own icon instead of default ?
E.g. - we are using this line

It give us default icon of HIGHLIGHT , so can we replace this icon with own icon ?

Yes, to replace any resources, you can place a new icon with the same name that is in the library in your application’s “res/drawable” folder, in this case, you’ll want to have your icon as vector drawable, and have the file name as “ic_annotation_free_highlight_black_24dp”. So in your application, you should have “res/drawable/ic_annotation_free_highlight_black_24dp.xml” that is your new icon. Could you please give it a try? Thanks.

FYI - it is possible to find names of existing resources in our download package: