繁体   English   中英

如何使按钮打开 android 工作室资产上的 PDF 文件中的特定页面?

[英]How can I make a button open a specific page in PDF file which is on assets in android studio?

**我在我的 android 应用程序的资产中有一个 PDF 文件。 我想使用按钮在 PDF 中的特定页面打开,因为滚动时间太长**

正如您所说,您正在使用AndroidPDFViewer 所以只需使用下面的代码。 另外我假设您已经为此创建了一个按钮

Button button = findViewById(R.id.button); 
PdfView pdfView = findViewById(r.id.pdfView);
//other parts

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pdfView.jumpTo(your_pageno);//this line helps to jump to any page of the pdf
        }
    });

编辑

如果您在不同的活动中有按钮和 pdfView,那么您可以将其用作

  • MainActivity 内部

    button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), pdfActivity.class); intent.putExtra("pageno", 5); // add this to pass the page number startActivity(intent); } });
  • 里面pdfActivity

     pdfView = findViewById(R.id.mypdf); pdfView.fromAsset("SAMPLE_FILE.pdf").defaultPage(getIntent().getIntExtra("pageno",0)) // this is used to scroll to the page required.enableAnnotationRendering(true).scrollHandle(new DefaultScrollHandle(this)).load();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM