android pdf 阅读器开发, pdf demo, pdf第三方控件
16lz
2021-12-04
demo library 下载
Activity调用的方法
public class PDFActivity extends Activity implements OnPageChangeListener {public static final String PDF_NAME = "xxx.pdf";// 书名private PDFView pdfView;private TextView pdf_tv_num;private int bookPage = 1;public final static String BOOKID = "bookId";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_pdf);pdfView = (PDFView) findViewById(R.id.pdfView);pdf_tv_num = (TextView) findViewById(R.id.pdf_tv_num);String bId = mCache.getAsString("pdfPage");// 获取上次读取的页数if (!isNEB(bId)) {bookPage = Integer.parseInt(bId);}String path = activity.getFilesDir().getAbsolutePath();// 获取路径File file = new File(path, PDF_NAME);if (file.exists()) {pdfView.fromFile(file).defaultPage(bookPage).onPageChange(this).load();// 显示要看的第几页}}public void onPageChanged(int page, int pageCount) {bookPage = page;pdf_tv_num.setText(page + "/" + pageCount);// page正在看的页数,pageCount总页数}@Overrideprotected void onStop() {super.onStop();// TODO 这里先保存的页数 bookPage// 如果退出要删除pdf,执底下的代码,否则不需要String path = activity.getFilesDir().getAbsolutePath();File file = new File(path, PDF_NAME);if (file.exists()) {file.delete();finish();}}}布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <com.joanzapata.pdfview.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/> <TextView android:id="@+id/pdf_tv_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="10dp" android:textColor="#000000" android:textSize="12sp" /></RelativeLayout>demo library 下载
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- Android(安卓)经典小技巧总结
- Android获取ROOT权限
- Android(安卓)获取url中的参数
- 2010.12.26——— android 获得手机号码 和 IMEI号 等
- Android(安卓)经典小技巧总结
- Android获取当前网络状态和获取当前设备网络ip地址
- eclipse中安装android ADT插件及无法下载ADT解决方法
- android TextUtils的使用