首页 > 解决方案 > 如何在Android中以只读模式显示pdf

问题描述

因为我有 3 个选项可以在 android 中显示 pdf 文件,例如:

1)Webview 2)Action_View 使用 Intent 3)使用这个库 'com.github.barteksc:android-pdf-viewer:2.8.2'

在 Web 视图中,有一些我不需要的默认选项。使用意图在 pdf 查看器或 word 应用程序中显示 pdf 文件,这提供了很多选择。最后一个,图书馆在android x中不起作用。

请提供解决方案,仅在 android 中显示 pdf 而没有任何共享、下载等类型选项。 使用 Webview 的 图像 使用 Intent的图像

标签: androidpdf

解决方案


我正在使用你提到的 androidx 库,我没有任何错误

实现 'com.github.barteksc:android-pdf-viewer:2.8.2'

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PDFViewActivity">

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

推荐阅读