Customize toolbar in Android PDF viewer

Example of how to alter the contextual toolbar menu’s items structure and how to toggle the visibility of items. Displayed on AnnotationCreationToolbar. Get additional resources by visiting our guide on customizing toolbar in Android PDF viewer.


/*
* Copyright © 2016-2025 PSPDFKit GmbH. All rights reserved.
*
* The PSPDFKit Sample applications are licensed with a modified BSD license.
* Please see License for details. This notice may not be removed from this file.
*/
package com.pspdfkit.catalog.examples.java;
import static com.pspdfkit.catalog.tasks.ExtractAssetTask.extract;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.annotation.NonNull;
import com.pspdfkit.catalog.R;
import com.pspdfkit.catalog.SdkExample;
import com.pspdfkit.catalog.examples.java.activities.CustomToolbarIconGroupingActivity;
import com.pspdfkit.configuration.activity.PdfActivityConfiguration;
import com.pspdfkit.ui.PdfActivityIntentBuilder;
/**
* Example of how to alter contextual toolbar menu items structure. Displayed on
* AnnotationCreationToolbar.
*/
public class CustomToolbarIconGroupingExample extends SdkExample {
public CustomToolbarIconGroupingExample(@NonNull Context context) {
super(
context.getString(R.string.customToolbarItemGroupingExampleTitle),
context.getString(R.string.customToolbarItemGroupingExampleDescription));
}
@Override
public void launchExample(
@NonNull final Context context, @NonNull final PdfActivityConfiguration.Builder configuration) {
// We use a custom utility class to extract the example document from the assets.
extract(WELCOME_DOC, getTitle(), context, documentFile -> {
// To start the DarkThemeActivity create a launch intent using the builder.
final Intent intent = PdfActivityIntentBuilder.fromUri(context, Uri.fromFile(documentFile))
.configuration(configuration.build())
.activityClass(CustomToolbarIconGroupingActivity.class)
.build();
// Start the DarkThemeActivity for the extracted document.
context.startActivity(intent);
});
}
}

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.