Text-to-Speech

The Android PDF text-to-speech feature is enabled by default. To disable the text-to-speech action in the TextSelectionToolbar, you need to register an OnContextualToolbarLifecycleListener on your activity and filter the action right before the toolbar is displayed. More details on this technique can be found in our toolbar customization guide:

Copy
1
2
3
4
5
override fun onPrepareContextualToolbar(toolbar: ContextualToolbar<*>) {
    (toolbar as TextSelectionToolbar?)?.setMenuItemGroupingRule { flatItems, _ ->
        flatItems.filter { it.id != R.id.pspdf__text_selection_toolbar_item_speak }
    }
}
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Override
public void onPrepareContextualToolbar(@NonNull ContextualToolbar toolbar) {
    if(toolbar instanceof TextSelectionToolbar) {
        toolbar.setMenuItemGroupingRule(new MenuItemGroupingRule() {
            @NonNull
            @Override
            public List<ContextualToolbarMenuItem> groupMenuItems(@NonNull List<ContextualToolbarMenuItem> flatItems, int capacity) {
                final List <ContextualToolbarMenuItem> filteredItems = new ArrayList<>();
                for(ContextualToolbarMenuItem item : flatItems) {
                    if(item.getId() != R.id.pspdf__text_selection_toolbar_item_speak) filteredItems.add(item);
                }
                return filteredItems;
            }
        });
    }
}
Text Speech