4/14每日总结(app实现浏览功能)

发布时间 2023-04-15 00:23:45作者: 南北啊

把pdf导入assets文件里面

然后在build gradle导入依赖:

implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

  在setting.gradle写进去

 jcenter()

  在gradle 。properties导入

# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

  MainActivity

package com.he.liu;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.github.barteksc.pdfviewer.PDFView;
import com.he.liu.R;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PDFView pdfView = findViewById(R.id.pdf);
        pdfView.fromAsset("优秀团员(1).pdf").load();
    }
}

  xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/pdf"/>
</RelativeLayout>