---
title: "Overriding hyperlink behavior in Android"
canonical_url: "https://www.nutrient.io/guides/android/knowledge-base/override-hyperlink-behavior/"
md_url: "https://www.nutrient.io/guides/android/knowledge-base/override-hyperlink-behavior.md"
last_updated: "2026-05-30T02:20:01.161Z"
description: "This guide addresses a common query of how to override hyperlink behavior in Android, especially for long-press actions."
---

This guide addresses a common query of how to override hyperlink behavior in Android, especially for long-press actions. It’ll outline how to customize both click and long-press interactions with hyperlinks.

## Analysis

While overriding the click behavior of hyperlinks is straightforward, the long-press action presents an additional challenge:

- The SDK provides a default long-press menu for hyperlinks, offering **Copy** and **Open** as options.

- This menu appears independent of the `onPageClick` callback, which only handles single clicks.

- As a result, the **Open** action from this menu bypasses any custom click handling you may have implemented.

## Solution

We offer a long-press listener, [`setOnDocumentLongPressListener`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/set-on-document-long-press-listener.html), and it should work the same as with the single click.

- You can override click behavior with the following code:

  ```kotlin

  requirePdfFragment().setOnDocumentLongPressListener { document, pageIndex, event, pagePosition, longPressedAnnotation ->
      longPressedAnnotation is LinkAnnotation
  }
  ```

## Summary

By implementing both click and long-press listeners, you can create a consistent and customized experience for hyperlink interactions in your Nutrient-powered Android application. This approach gives you full control over how hyperlinks behave, whether they’re tapped or long-pressed.

Remember to test your implementation thoroughly to ensure it meets your specific requirements and provides a smooth user experience.

If you encounter any issues or have further questions about customizing hyperlink behavior, don’t hesitate to reach out to our [Support team](https://support.nutrient.io/hc/en-us/requests/new).
---

## Related pages

- [Deleting Pages From A Pdf](/guides/android/knowledge-base/deleting-pages-from-a-pdf.md)
- [Easily disable share and print options in Android](/guides/android/knowledge-base/disable-share-documentinfo-print.md)
- [Allow Clear Text Traffic](/guides/android/knowledge-base/allow-clear-text-traffic.md)
- [Custom Print Functionality](/guides/android/knowledge-base/custom-print-functionality.md)
- [Compose Qna](/guides/android/knowledge-base/compose-qna.md)
- [Disabling Annotation Rotation](/guides/android/knowledge-base/disabling-annotation-rotation.md)
- [Managing touch scrolling in Compose containers](/guides/android/knowledge-base/document-view-inside-pager-scroll-handling.md)
- [Getting All Digital Signatures](/guides/android/knowledge-base/getting-all-digital-signatures.md)
- [Change page layout dynamically based on orientation](/guides/android/knowledge-base/dynamic-page-layout-when-changing-orientation.md)
- [Getting Signature Location](/guides/android/knowledge-base/getting-signature-location.md)
- [Invoke Search Programmatically](/guides/android/knowledge-base/invoke-search-programmatically.md)
- [Install Failed Insufficient Storage](/guides/android/knowledge-base/install-failed-insufficient-storage.md)
- [Making Form Elements Read Only](/guides/android/knowledge-base/making-form-elements-read-only.md)
- [Intercepting Touch Events](/guides/android/knowledge-base/intercepting-touch-events.md)
- [Invoking Share Action Programmatically](/guides/android/knowledge-base/invoking-share-action-programmatically.md)
- [Creating invisible digital signatures in Android](/guides/android/knowledge-base/invisible-signature.md)
- [Runtime Permissions Cordova](/guides/android/knowledge-base/runtime-permissions-cordova.md)
- [Save signed PDFs directly to a remote server on Android](/guides/android/knowledge-base/save-signed-pdfs-to-remote-server.md)
- [Remove Tool Variant From Toolbar](/guides/android/knowledge-base/remove-tool-variant-from-toolbar.md)
- [Using Pspdfkit With Dynamic Feature Modules](/guides/android/knowledge-base/using-pspdfkit-with-dynamic-feature-modules.md)
- [Customize the overflow button color in Android](/guides/android/knowledge-base/styling-overflow-button.md)

