How to Invoke the Search UI in the PdfActivity Programmatically

If you want to show the search view and/or start search in the search view, you can use the following method in PdfActivity.

You’ll need to register the PSPDFView’s visibility change listener to begin searching immediately after the search view is shown:

pspdfKitViews.addOnVisibilityChangedListener(object : OnVisibilityChangedListener {
    override fun onShow(view: View) {
        if (view is PdfSearchViewInline) {
            view.setInputFieldText("query", true)
        } else if (view is PdfSearchViewModular) {
            view.setInputFieldText("query", true)
        }
        pspdfKitViews.removeOnVisibilityChangedListener(this)
    }

    override fun onHide(view: View) {
    }
})

You can then show the search view via the following:

pspdfKitViews.showView(PSPDFKitViews.Type.VIEW_SEARCH)

If you want to invoke search programmatically, or if you want to build a custom search user interface (UI), refer to our text search guide, which explains all the aspects of search and how to integrate it into your UI.