Some test text!
All actions related to the PDF viewer are handled through the
PdfViewCtrlTabHostFragment fragment. This fragment extends
android.support.v4.app.Fragment and is responsible for showing document in tabs.
Please note that
PdfViewCtrlTabHostFragment requires the
First, make sure the following is in your
<application> tag in
<application ... android:largeHeap="true"> ... <activity ... android:windowSoftInputMode="adjustPan" /> </application>
AppCompattheme for material colors. Make sure that the value of
activitytag also extends the
PdfViewCtrlTabHostFragment in an activity is straightforward. Like any other fragment you should make an instance of the class and attach it to the activity. To create an instance of the host fragment you need to pass in a bundle that can be created using
createBasicPdfViewCtrlTabBundle. The bundle specifies the document that should be shown when the host fragment is visible. For example, to open a document in the host fragment when you know the URI of the file (and its password if the file is password protected) you can call:
You can simply convert a file to a URI by:
If you would like to customize the UI of
PdfViewCtrlTabHostFragment, you can use
ViewerConfig builder. For example:
For details on customizing the UI interface and sample usage of
ViewerConfig builder, check out the configuration tutorial.
The default toolbar menu consists of menu items for
However, you can fully customize and control the toolbar menu as well as the navigation icon.
In order to change the default toolbar menu items you need to create your own menu in menu resource folder and pass it to the host fragment through bundle:
To change the navigation icon, similar to the toolbar menu, you need to pass the desired icon to the host fragment through the bundle:
If you want to interact with the host fragment you should call
addHostListener(TabHostListener) and override those methods that you are interested in. For example, you may want to override
onToolbarOptionsItemSelected(MenuItem) when you add a new menu item, so when the item is clicked you can get a callback. As another example, you can get the callback when the navigation icon is clicked if you override
Here's an example that replaces the default navigation icon, and only keeps the annotation toolbar icon in the toolbar menu while adding a new menu item to show a toast when selected:
fragment_viewer_simple.xml should be placed in menu resource folder and contain:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_annotation_toolbar" android:icon="@drawable/ic_mode_edit_white" android:title="@string/action_annotation_toolbar" app:showAsAction="ifRoom"/> <item android:id="@+id/action_show_toast" android:title="Show toast" app:showAsAction="never" /> </menu>
With this complete, you will see: