我尝试使用 [bartecksc AndroidPdfViewer][1]
[1]:https : //github.com/barteksc/AndroidPdfViewer在我的 android 应用程序中从应用程序内的资产文件夹中查看 PDF 文件,但它不起作用。它显示一个空白屏幕。这是我所做的:我在 build.gradle 文件中添加了这个依赖项
implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
Run Code Online (Sandbox Code Playgroud)
(我什至尝试使用implementation 'com.github.barteksc:android-pdf-viewer:2.8.2')
我在 activity_main.xml 中添加了以下小部件
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Run Code Online (Sandbox Code Playgroud)
我将以下代码放在 onCreate 方法中
PDFView pdfView=findViewById(R.id.pdfView);
pdfView.fromAsset("sample_file.pdf");
Run Code Online (Sandbox Code Playgroud)
我想显示的文件位于名为 sample_file.pdf 的资产文件夹中
以下是我的 MainActivity.java
package com.umersoftwares.bartekscpdfview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.github.barteksc.pdfviewer.PDFView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PDFView pdfView=findViewById(R.id.pdfView);
pdfView.fromAsset("sample_file.pdf");
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我的activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".MainActivity">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="fill_parent" …Run Code Online (Sandbox Code Playgroud) android ×1