This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/customizing-the-interface/extending-pdfactivity.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Extending PdfActivity with custom activities

Displaying documents using the PdfActivity is sufficient in most cases. Nonetheless, some situations need customizations beyond pure styling. For more flexibility, you can extend the PdfActivity and implement your own custom activities.

A PdfActivity and any activities deriving from it need special intent data (document sources, passwords, configuration, etc.). Create a launch Intent with the PdfActivityIntentBuilder to carry all of this information. The builder sets your activity class through its #activity method. For a comprehensive example of what is possible with customization, take a look at the CustomLayoutExample or the MainToolbarCustomizationExample inside the Catalog app.

Creating your activity

The first step for implementing a custom activity is to subclass the PdfActivity. Your custom activity doesn’t need to define or inflate a layout, because the PdfActivity parent class sets it up. To use a custom layout, pass it with PdfActivityConfiguration.Builder#layout when launching the activity. Toolbar customization goes through the items API described in customizing the main toolbar; the activity has no options menu.

class MyCustomActivity : PdfActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Custom main toolbar items; see the main toolbar guide.
setToolbarItemsProvider { defaultItems -> defaultItems + myItem }
setOnToolbarItemClickListener { id -> id == R.id.my_item && handleMyItem() }
}
override fun onDocumentLoaded(document: PdfDocument) {
// Document is ready to use.
}
override fun onDocumentLoadFailed(exception: Throwable) {
// Add your fancy error handling here.
}
}

Next, you need to add this activity to your AndroidManifest.xml so you can launch it. You can also define the android:theme property to set a custom theme:

<activity
android:name="com.pspdfkit.example.MyCustomActivity"
android:label="@string/title_activity_custom"
android:theme="@style/MyApp.Theme" />

To launch MyCustomActivity, first create a PdfActivityConfiguration, then create a launching intent using the PdfActivityIntentBuilder, and finally call Activity#startActivity(opens in a new tab) with the intent you created:

val config = PdfActivityConfiguration.Builder(context).build()
val intent = PdfActivityIntentBuilder.fromUri(context, uri)
.configuration(config)
.activity(MyCustomActivity::class.java)
.build()
// Start the `MyCustomActivity` like any other activity.
context.startActivity(intent)

Custom activity layouts

By default, PdfActivity uses the R.layout.pspdf__pdf_activity as its layout file. Have a look at that file to see all the views Nutrient uses. You can use the file as a template for your custom layout. To specify the layout, provide its ID to the PdfActivityConfiguration.Builder#layout method. Usually, it also makes sense to subclass the PdfActivity so it can make use of the custom layout and the views you may add:

val config = PdfActivityConfiguration.Builder(context)
.layout(R.layout.my_custom_layout)
.build()

Required views

The PdfActivity expects several views to be present in the selected layout file. If any of the following views is missing, Nutrient throws an InvalidLayoutException:

View IDDescription
@id/pspdf__toolbar_compose_hostAn androidx.compose.ui.platform.ComposeView that hosts the main toolbar and the contextual toolbars, including their docking and drag chrome. It must overlay the content, match_parent in both directions; it paints nothing and lets touches through where no toolbar is shown.
@id/pspdf__inspector_coordinatorPropertyInspectorCoordinatorLayout for managing and laying out the PropertyInspector views.
@id/pspdf__activity_fragment_containerViewGroup(opens in a new tab) or any subclass. The activity will use this to inject the PdfFragment.
<androidx.compose.ui.platform.ComposeView
android:id="@+id/pspdf__toolbar_compose_host"
android:layout_width="match_parent"
android:layout_height="match_parent" />

No toolbar View exists to reference: The main toolbar is composed inside pspdf__toolbar_compose_host, and the inline search bar is part of it. Customize its items and appearance through the main toolbar and appearance styling guides.

Optional views

In addition to the mandatory views, the layout may define several optional views. If you remove one of them from your layout, disable its feature with the PdfActivityConfiguration.Builder. Otherwise, the activity throws an InvalidLayoutException for the enabled feature:

View IDDescription
@id/pspdf__activity_thumbnail_barThe PdfThumbnailBar for displaying a horizontal list of thumbnails that show the current page.
@id/pspdf__activity_page_overlayA TextView(opens in a new tab) for displaying the current page and total page count (e.g. Page 4 of 22).
@id/pspdf__activity_thumbnail_gridThe PdfThumbnailGrid, the document overview and document editor. Required while thumbnailGridEnabled(true).
@id/pspdf__activity_search_view_modularA PdfSearchViewModular for displaying a search box and a list of search results. Used with SearchType.MODULAR; inline search needs no view.
@id/pspdf__activity_outline_viewThe PdfOutlineView, the entry point for the outline sheet with the table of contents, bookmarks, annotations, and document info. Required while outlineEnabled(true).
@id/pspdf__activity_document_info_viewThe document info view, when the document info is shown separately from the outline.
@id/pspdf__navigate_back and @id/pspdf__navigate_forwardCardView(opens in a new tab)s that display the buttons for navigating back and forward. Required while navigationButtonsEnabled(true).
@id/pspdf__activity_tab_barThe PdfTabBar for displaying a horizontal list of document tabs.
@id/pspdf__activity_form_editing_barThe FormEditingBar for filling out interactive forms.
@id/pspdf__activity_content_editing_barThe styling bar shown while editing text content.
@id/pspdf__activity_reader_viewThe reader view.

The document title overlay is rendered inside the main toolbar and has no view of its own. The layout the SDK ships, R.layout.pspdf__pdf_activity, is the reference for the complete set; the Catalog app’s CustomLayoutExample uses a custom layout.